cat_dev/mion/proto/cgis/
errors.rs1use bytes::Bytes;
4use mac_address::MacParseError;
5use miette::Diagnostic;
6use serde_urlencoded::ser::Error as SerdeUrlEncodeError;
7use std::{net::AddrParseError, num::ParseIntError};
8use thiserror::Error;
9
10#[derive(Debug, Diagnostic, Error, PartialEq, Eq)]
12pub enum MIONCGIErrors {
13 #[error("Failed to encode data as form data: {0}")]
15 #[diagnostic(code(cat_dev::net::parse::mion::cgi::encode::form_data_error))]
16 FormDataEncodeError(#[from] SerdeUrlEncodeError),
17 #[error("Could not parse byte from memory dump: {0}")]
23 #[diagnostic(code(cat_dev::net::parse::mion::cgi::bad_memory_byte))]
24 HtmlResponseBadByte(String),
25 #[error("Expected HTML Response to have an IP as a string, but could not parse: `{0:?}`")]
28 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_ip_encoding_error))]
29 HtmlResponseIpExpectedButNotThere(AddrParseError),
30 #[error("Expected HTML Response to have a MAC as a string, but could not parse: `{0:?}`")]
33 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_mac_encoding_error))]
34 HtmlResponseMacExpectedButNotThere(MacParseError),
35 #[error("Could not parse HTML response could not find one of the body tags: `<body>`, or `</body>`: {0}")]
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("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.")]
52 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_version_prefix))]
53 HtmlResponseMissingVersionPart(String, String),
54 #[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:?}")]
55 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_missing_versions))]
56 HtmlResponseMissingVersions(Vec<String>),
57 #[error("Expected HTML Response to have a radio button, could not parse: `{0}`")]
60 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_radio_wasnt_checked))]
61 HtmlResponseNoRadioChecked(String),
62 #[error("Expected HTML Response to have a table item with prefix: {1}, but couldn't find one in: `{0}`")]
65 HtmlResponseNoTableItemWithPrefix(String, String),
66 #[error("Expected HTML Response to have an number as a string, but could not parse: `{0:?}`")]
69 #[diagnostic(code(cat_dev::net::parse::mion::cgi::html_response_number_encoding_error))]
70 HtmlResponseNumberExpectedButNotThere(ParseIntError),
71 #[error("Got an unexpected status code that wasn't successful over HTTP: {0}, Body: {1:02x?}")]
74 #[diagnostic(code(cat_dev::net::parse::mion::cgi::status_code))]
75 UnexpectedStatusCode(u16, Bytes),
76 #[error("Got an unexpected status code that wasn't successful over HTTP: {0}")]
79 #[diagnostic(code(cat_dev::net::parse::http::bad_status_code_without_body))]
80 UnexpectedStatusCodeNoBody(u16),
81}