Skip to content

Commit

Permalink
Oops
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Feb 24, 2024
1 parent b961a1b commit b40df6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
5 changes: 0 additions & 5 deletions cargo-espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,24 @@ pub enum Error {
}

/// TOML deserialization error
#[cfg(feature = "cli")]
#[derive(Debug)]
pub struct TomlError {
err: toml::de::Error,
source: String,
}

#[cfg(feature = "cli")]
impl TomlError {
pub fn new(err: toml::de::Error, source: String) -> Self {
Self { err, source }
}
}

#[cfg(feature = "cli")]
impl Display for TomlError {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
write!(f, "Failed to parse toml")
}
}

#[cfg(feature = "cli")]
impl Diagnostic for TomlError {
fn source_code(&self) -> Option<&dyn SourceCode> {
Some(&self.source)
Expand All @@ -96,7 +92,6 @@ impl Diagnostic for TomlError {
}

// NOTE: no `source` on purpose to prevent duplicating the message
#[cfg(feature = "cli")]
impl std::error::Error for TomlError {}

/// Unsupported target error
Expand Down
4 changes: 2 additions & 2 deletions espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ serde = { version = "1.0.196", features = ["derive"] }
serialport = { version = "4.3.0", optional = true }
sha2 = "0.10.8"
slip-codec = { version = "0.4.0", optional = true }
strum = { version = "0.26.1", features = ["derive"], optional = true }
strum = { version = "0.26.1", features = ["derive"] }
thiserror = "1.0.56"
toml = { version = "0.8.10", optional = true }
update-informer = { version = "1.1.0", optional = true }
Expand Down Expand Up @@ -84,7 +84,7 @@ cli = [
]

# enables connecting to a device via serial port
serialport = ["flashing", "dep:serialport", "dep:slip-codec", "dep:regex", "dep:strum"]
serialport = ["flashing", "dep:serialport", "dep:slip-codec", "dep:regex"]

# enables flash stubs and stub commands
flashing = ["xmas-elf", "dep:toml"]
15 changes: 7 additions & 8 deletions espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use std::{
use miette::Diagnostic;
#[cfg(feature = "serialport")]
use slip_codec::SlipError;
#[cfg(feature = "serialpot")]
use strum::FromRepr;
use strum::VariantNames;
use thiserror::Error;

#[cfg(feature = "cli")]
Expand Down Expand Up @@ -185,7 +184,7 @@ pub enum Error {
InvalidElf(#[from] ElfError),

#[error("The bootloader returned an error")]
#[cfg(feature = "serialpot")]
#[cfg(feature = "serialport")]
#[diagnostic(transparent)]
RomError(#[from] RomError),

Expand Down Expand Up @@ -350,10 +349,10 @@ impl From<CommandType> for TimedOutCommand {
}

/// Errors originating from a device's ROM functionality
#[derive(Clone, Copy, Debug, Default, Diagnostic, Error, FromRepr)]
#[derive(Clone, Copy, Debug, Default, Diagnostic, Error, strum::FromRepr)]
#[non_exhaustive]
#[repr(u8)]
#[cfg(feature = "serialpot")]
#[cfg(feature = "serialport")]
pub enum RomErrorKind {
#[error("Invalid message received")]
#[diagnostic(code(espflash::rom::invalid_message))]
Expand Down Expand Up @@ -429,7 +428,7 @@ pub enum RomErrorKind {
Other = 0xff,
}

#[cfg(feature = "serialpot")]
#[cfg(feature = "serialport")]
impl From<u8> for RomErrorKind {
fn from(raw: u8) -> Self {
Self::from_repr(raw).unwrap_or_default()
Expand All @@ -439,15 +438,15 @@ impl From<u8> for RomErrorKind {
/// An error originating from a device's ROM functionality
#[derive(Clone, Copy, Debug, Diagnostic, Error)]
#[error("Error while running {command} command")]
#[cfg(feature = "serialpot")]
#[cfg(feature = "serialport")]
#[non_exhaustive]
pub struct RomError {
command: CommandType,
#[source]
kind: RomErrorKind,
}

#[cfg(feature = "serialpot")]
#[cfg(feature = "serialport")]
impl RomError {
pub fn new(command: CommandType, kind: RomErrorKind) -> RomError {
RomError { command, kind }
Expand Down

0 comments on commit b40df6a

Please sign in to comment.