Skip to content

Commit b591332

Browse files
George Cosmaeva-cosma
authored andcommitted
chore: document new errors
Signed-off-by: George Cosma <george.cosma@wyliodrin.com>
1 parent 777ec94 commit b591332

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tockloader-lib/src/errors.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,37 @@ use thiserror::Error;
88
// Rule of thumb: for public-facing functions or API use `TockloaderError`. For
99
// crate-public/private functions you can use more specific errors.
1010

11+
/// Represents all possible errors that can occur within the Tockloader context.
1112
#[derive(Debug, Error)]
1213
pub enum TockloaderError {
14+
/// Represents an error that can occur during serial communication. This
15+
/// does not include errors stemming from bad data or bad bootloader.
1316
#[error("Serial connection error: {0}")]
1417
Serial(#[from] SerialError),
1518

19+
/// Represents an error that can occur while interacting with a probe. This
20+
/// does not include errors stemming from bad data.
1621
#[error("Probe connection error: {0}")]
1722
Probe(#[from] ProbeError),
1823

24+
/// Represents an error that can occur while parsing a tab file.
1925
#[error("TAB file error: {0}")]
2026
Tab(#[from] TabError),
2127

28+
/// Represents an error that can occur while parsing Tock OS data or
29+
/// otherwise coming from a misconfigured of Tock OS.
2230
#[error("Tock OS error: {0}")]
2331
Tock(#[from] TockError),
2432

33+
/// Represents an error that occurs from internal violations of assumptions,
34+
/// or inconsistent state. It usually represents something that the user of
35+
/// this library did wrong.
2536
#[error("Internal tockloader error: {0}")]
2637
Internal(#[from] InternalError),
2738
}
2839

40+
/// Represents errors that can occur during serial communication. This does not
41+
/// include errors stemming from bad data or bad bootloader.
2942
#[derive(Debug, Error)]
3043
pub enum SerialError {
3144
#[error("Failed to interface in serial using tokio_serial: {0}")]
@@ -35,6 +48,8 @@ pub enum SerialError {
3548
IO(#[from] io::Error),
3649
}
3750

51+
/// Represents errors that can occur while interacting with a probe. This does
52+
/// not include errors stemming from bad data.
3853
#[derive(Debug, Error)]
3954
pub enum ProbeError {
4055
#[error("Failed to interact with probe: {0}")]
@@ -47,6 +62,7 @@ pub enum ProbeError {
4762
Flashing(#[from] probe_rs::flashing::FlashError),
4863
}
4964

65+
/// Represents errors that can occur while parsing a tab file.
5066
#[derive(Debug, Error)]
5167
pub enum TabError {
5268
#[error("Failed to use tab due to IO error: {0}")]
@@ -65,6 +81,8 @@ pub enum TabError {
6581
MissingBinary(String),
6682
}
6783

84+
/// Represents errors that can occur while parsing Tock OS data or otherwise
85+
/// coming from a misconfigured of Tock OS.
6886
#[derive(Debug, Error)]
6987
pub enum TockError {
7088
#[error("Bootloader returned an invalid header: {0} {1}")]
@@ -83,6 +101,7 @@ pub enum TockError {
83101
MissingAttribute(String),
84102
}
85103

104+
/// Represents errors that can occur while parsing attributes.
86105
#[derive(Debug, Error)]
87106
pub enum AttributeParseError {
88107
#[error("Expected attribute to be a valid number. Inner: {0}")]
@@ -92,6 +111,8 @@ pub enum AttributeParseError {
92111
InvalidString(#[from] std::string::FromUtf8Error),
93112
}
94113

114+
/// Represents internal violations of assumptions, or inconsistent state. It
115+
/// usually represents something that the user of this library did wrong.
95116
#[derive(Debug, Error)]
96117
pub enum InternalError {
97118
#[error("Operation failed due to board not being open.")]

0 commit comments

Comments
 (0)