cat_dev/mion/proto/cgis/
errors.rs

1//! Errors related to CGI, and HTML pages for the MION.
2
3use bytes::Bytes;
4#[cfg(feature = "clients")]
5use mac_address::MacParseError;
6use miette::Diagnostic;
7use std::{net::AddrParseError, num::ParseIntError};
8use thiserror::Error;
9
10/// Errors related to handling and dealing with the HTML CGI pages.
11#[derive(Debug, Diagnostic, Error, PartialEq, Eq)]
12pub enum MionCGIErrors {
13	/// The HTML response we got was expected to contain hexadecimal bytes.
14	///
15	/// We could not parse one of these hexadecimal bytes. Either the device
16	/// responded with an error we didn't properly pick up on, or we got corrupt
17	/// data somehow.,
18	#[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	/// We expected this HTML response to have an IP encoded as a string, but we
22	/// could not parse the string as an IP.
23	#[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	/// We expected this HTML response to have a MAC Address encoded as a string,
27	/// but we could not parse the string as a MAC address.
28	#[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	/// We could not find the `<body>` tags in a page that is supposed to return
34	/// HTML.
35	#[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	/// We attempted to find an `<input>` element with a certain name in the
47	/// HTML response, but were not able to find one.
48	#[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	/// We expected the HTML response to have one radio box checked out of all
62	/// the radio boxes, but we found no radio boxes that were checked.
63	#[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	/// We expected to find an item in a table `<tr>`/`<td>`, but were not able
67	/// to find one in the HTML response we got back.
68	#[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	/// We expected this HTML response to have a number encoded as a string, but we
73	/// could not parse the string as a number.
74	#[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	/// There are only so many sizes a cat-dev HDD bank can come in, these are
78	/// hardcoded. You've specified a bank we can't set.
79	#[error("Unknown ID for Cat-DEV Bank Sizes: [{0}]")]
80	#[diagnostic(code(cat_dev::api::mion::cgi::unknown_bank_size))]
81	UnknownCatDevBankSizeId(u32),
82	/// There are a series of operations you can call on `control.cgi`,
83	/// unfortunately the one specified is not an operation we know on
84	/// any firmware version.
85	#[error("Unknown operation for `control.cgi`: [{0}]")]
86	#[diagnostic(code(cat_dev::api::mion::cgi::control::unknown_operation))]
87	UnknownControlOperation(String),
88	/// We got an unexpected status code from the CAT-DEV, it also came with an
89	/// HTTP body that may contain clues to it's error.
90	#[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	/// There are a series of operations you can call on `status.cgi`,
94	/// unfortunately the one specified is not an operation we know on
95	/// any firmware version.
96	#[error("Unknown operation for `status.cgi`: [{0}]")]
97	#[diagnostic(code(cat_dev::api::mion::cgi::status::unknown_operation))]
98	UnknownStatusOperation(String),
99	/// We got an unexpected status code from the CAT-DEV, this is only used when
100	/// we did not get an HTTP body back from the CAT-DEV as well.
101	#[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}