Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

lib: Print better error for invalid baudrate #53

Merged
Merged
Changes from all 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
12 changes: 10 additions & 2 deletions espmonitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ fn run_child(args: AppArgs) -> Result<(), Box<dyn std::error::Error>> {

let mut dev = serial::open(&args.serial)?;
dev.set_timeout(Duration::from_millis(200))?;
dev.reconfigure(&|settings| {
settings.set_baud_rate(speed)

// The only thing we reconfigure and that could thus cause an error is the baud rate setting.
// Hence we can explicitly handle this case here and give the user a better idea of which part
// of their input was actually invalid.
dev.reconfigure(&|settings| settings.set_baud_rate(speed)).map_err(|err| {
if let serial::ErrorKind::InvalidInput = err.kind() {
format!("Baud rate {} not supported by hardware", speed.speed())
} else {
format!("{}", err)
}
})?;

let bin_data = args.bin.as_ref().and_then(|bin_name| match fs::read(bin_name) {
Expand Down