cat_dev/mion/proto/cgis/
errors.rs1use bytes::Bytes;
4#[cfg(feature = "clients")]
5use mac_address::MacParseError;
6use miette::Diagnostic;
7use std::{net::AddrParseError, num::ParseIntError};
8use thiserror::Error;
9
10#[derive(Debug, Diagnostic, Error, PartialEq, Eq)]
12pub enum MionCGIErrors {
13 #[error("Could not parse byte from memory dump: {0}")]
19 #[diagnostic(code(cat_dev::net::parse::mion::cgi::bad_memory_byte))]
20 HtmlResponseBadByte(String),
21 #[error("Expected HTML Response to have an IP as a string, but could not parse: `{0:?}`")]
24 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_ip_encoding_error))]
25 HtmlResponseIpExpectedButNotThere(AddrParseError),
26 #[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
29 #[cfg(feature = "clients")]
30 #[error("Expected HTML Response to have a MAC as a string, but could not parse: `{0:?}`")]
31 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_mac_encoding_error))]
32 HtmlResponseMacExpectedButNotThere(MacParseError),
33 #[error(
36 "Could not parse HTML response could not find one of the body tags: `<body>`, or `</body>`: {0}"
37 )]
38 #[diagnostic(code(cat_dev::net::parse::mion::cgi::no_body_tag))]
39 HtmlResponseMissingBody(String),
40 #[error("Expected to find closing tag: {0}, in the rest of the HTML Body: {1}")]
41 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_closing_tag))]
42 HtmlResponseMissingClosingTag(String, String),
43 #[error("Could not find Memory Dump Table Body, failed to find sigils: {0}")]
44 #[diagnostic(code(cat_dev::net::parse::mion::cgi::no_mem_dump_sigil))]
45 HtmlResponseMissingMemoryDumpSigil(String),
46 #[error("Could not find input with name: `{0}`, within HTML body: `{1}`")]
49 #[diagnostic(code(cat_dev::net::parse::mion::cgi::missing_tagged_input))]
50 HtmlResponseMissingTaggedInput(String, String),
51 #[error(
52 "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."
53 )]
54 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_version_prefix))]
55 HtmlResponseMissingVersionPart(String, String),
56 #[error(
57 "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:?}"
58 )]
59 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_versions))]
60 HtmlResponseMissingVersions(Vec<String>),
61 #[error("Expected HTML Response to have a radio button, could not parse: `{0}`")]
64 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_radio_wasnt_checked))]
65 HtmlResponseNoRadioChecked(String),
66 #[error(
69 "Expected HTML Response to have a table item with prefix: {1}, but couldn't find one in: `{0}`"
70 )]
71 HtmlResponseNoTableItemWithPrefix(String, String),
72 #[error("Expected HTML Response to have an number as a string, but could not parse: `{0:?}`")]
75 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_number_encoding_error))]
76 HtmlResponseNumberExpectedButNotThere(ParseIntError),
77 #[error("Unknown ID for Cat-DEV Bank Sizes: [{0}]")]
80 #[diagnostic(code(cat_dev::api::mion::cgi::unknown_bank_size))]
81 UnknownCatDevBankSizeId(u32),
82 #[error("Unknown operation for `control.cgi`: [{0}]")]
86 #[diagnostic(code(cat_dev::api::mion::cgi::control::unknown_operation))]
87 UnknownControlOperation(String),
88 #[error("Got an unexpected status code that wasn't successful over HTTP: {0}, Body: {1:02x?}")]
91 #[diagnostic(code(cat_dev::net::parse::mion::cgi::status_code))]
92 UnexpectedStatusCode(u16, Bytes),
93 #[error("Unknown operation for `status.cgi`: [{0}]")]
97 #[diagnostic(code(cat_dev::api::mion::cgi::status::unknown_operation))]
98 UnknownStatusOperation(String),
99 #[error("Got an unexpected status code that wasn't successful over HTTP: {0}")]
102 #[diagnostic(code(cat_dev::net::parse::http::bad_status_code_without_body))]
103 UnexpectedStatusCodeNoBody(u16),
104}