Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error for cases when we cant read the serial monitor trying to decode the bootmode #572

Merged
merged 4 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions espflash/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use std::{
io::{BufWriter, Write},
iter::zip,
str::from_utf8,
thread::sleep,
time::Duration,
};
Expand Down Expand Up @@ -132,9 +133,14 @@ impl Connection {
Ok(_) => {
return Ok(());
}
Err(e) => {
debug!("Failed to reset, error {:#?}, retrying", e);
}
Err(e) => match e {
Error::InvalidSerialRead => {
return Err(Error::InvalidSerialRead);
}
_ => {
debug!("Failed to reset, error {:#?}, retrying", e);
}
},
}
}

Expand Down Expand Up @@ -168,7 +174,10 @@ impl Connection {
)));
}

let read_slice = std::str::from_utf8(&buff[..read_bytes as usize]).unwrap();
let read_slice = from_utf8(&buff[..read_bytes as usize]).map_err(|err| {
debug!("Error: {}", err);
Error::InvalidSerialRead
})?;

let pattern = Regex::new(r"boot:(0x[0-9a-fA-F]+)(.*waiting for download)?").unwrap();

Expand Down
4 changes: 4 additions & 0 deletions espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ pub enum Error {
#[error("The provided bootloader binary is invalid")]
InvalidBootloader,

#[error("Invalid byte sequence read from the serial port while trying to detect Boot Mode")]
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
#[diagnostic(code(espflash::invalid_serial_read))]
InvalidSerialRead,

#[error("Specified bootloader path is not a .bin file")]
#[diagnostic(code(espflash::invalid_bootloader_path))]
InvalidBootloaderPath,
Expand Down
Loading