use bytes::Bytes;
#[cfg(feature = "clients")]
use mac_address::MacParseError;
use miette::Diagnostic;
use std::{net::AddrParseError, num::ParseIntError};
use thiserror::Error;
#[derive(Debug, Diagnostic, Error, PartialEq, Eq)]
pub enum MionCGIErrors {
#[error("Could not parse byte from memory dump: {0}")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::bad_memory_byte))]
HtmlResponseBadByte(String),
#[error("Expected HTML Response to have an IP as a string, but could not parse: `{0:?}`")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_ip_encoding_error))]
HtmlResponseIpExpectedButNotThere(AddrParseError),
#[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
#[cfg(feature = "clients")]
#[error("Expected HTML Response to have a MAC as a string, but could not parse: `{0:?}`")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_mac_encoding_error))]
HtmlResponseMacExpectedButNotThere(MacParseError),
#[error(
"Could not parse HTML response could not find one of the body tags: `<body>`, or `</body>`: {0}"
)]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::no_body_tag))]
HtmlResponseMissingBody(String),
#[error("Expected to find closing tag: {0}, in the rest of the HTML Body: {1}")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_closing_tag))]
HtmlResponseMissingClosingTag(String, String),
#[error("Could not find Memory Dump Table Body, failed to find sigils: {0}")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::no_mem_dump_sigil))]
HtmlResponseMissingMemoryDumpSigil(String),
#[error("Could not find input with name: `{0}`, within HTML body: `{1}`")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::missing_tagged_input))]
HtmlResponseMissingTaggedInput(String, String),
#[error(
"Expected to find a string to help identify the version in the HTML ({0}) as part of the string ({1}), but did not find one."
)]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_version_prefix))]
HtmlResponseMissingVersionPart(String, String),
#[error(
"When fetching the versions of the MION we expect to find both the FW version, and the FPGA version, but only found the following versions: {0:?}"
)]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_versions))]
HtmlResponseMissingVersions(Vec<String>),
#[error("Expected HTML Response to have a radio button, could not parse: `{0}`")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_radio_wasnt_checked))]
HtmlResponseNoRadioChecked(String),
#[error(
"Expected HTML Response to have a table item with prefix: {1}, but couldn't find one in: `{0}`"
)]
HtmlResponseNoTableItemWithPrefix(String, String),
#[error("Expected HTML Response to have an number as a string, but could not parse: `{0:?}`")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_number_encoding_error))]
HtmlResponseNumberExpectedButNotThere(ParseIntError),
#[error("Unknown ID for Cat-DEV Bank Sizes: [{0}]")]
#[diagnostic(code(cat_dev::api::mion::cgi::unknown_bank_size))]
UnknownCatDevBankSizeId(u32),
#[error("Unknown operation for `control.cgi`: [{0}]")]
#[diagnostic(code(cat_dev::api::mion::cgi::control::unknown_operation))]
UnknownControlOperation(String),
#[error("Got an unexpected status code that wasn't successful over HTTP: {0}, Body: {1:02x?}")]
#[diagnostic(code(cat_dev::net::parse::mion::cgi::status_code))]
UnexpectedStatusCode(u16, Bytes),
#[error("Unknown operation for `status.cgi`: [{0}]")]
#[diagnostic(code(cat_dev::api::mion::cgi::status::unknown_operation))]
UnknownStatusOperation(String),
#[error("Got an unexpected status code that wasn't successful over HTTP: {0}")]
#[diagnostic(code(cat_dev::net::parse::http::bad_status_code_without_body))]
UnexpectedStatusCodeNoBody(u16),
}