Skip to content

Commit b2ee154

Browse files
[windows] Don't crash during typing when the MCU isn't listening (#943)
* Don't crash during typing when the MCU isn't listening * Update CHANGELOG.md Co-authored-by: Sergio Gasquez Arcos <[email protected]> --------- Co-authored-by: Sergio Gasquez Arcos <[email protected]>
1 parent 1daf446 commit b2ee154

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Fixed
1717

18+
- [Windows] Fixed a crash in monitor when espflash is connected via USB Serial/JTAG, and the user is typing into the monitor but the device is not reading serial input. (#943)
19+
1820
### Removed
1921

2022
## [4.0.1] - 2025-07-07

espflash/src/cli/monitor/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! in our monitor the output is displayed immediately upon reading.
1212
1313
use std::{
14-
io::{ErrorKind, Read, Write, stdout},
14+
io::{self, ErrorKind, Read, Write, stdout},
1515
time::Duration,
1616
};
1717

@@ -173,14 +173,31 @@ fn handle_user_input(serial: &mut Port, pid: u16, non_interactive: bool) -> Resu
173173
}
174174

175175
if let Some(bytes) = handle_key_event(key) {
176-
serial.write_all(&bytes).into_diagnostic()?;
177-
serial.flush().into_diagnostic()?;
176+
serial
177+
.write_all(&bytes)
178+
.ignore_timeout()
179+
.into_diagnostic()?;
180+
serial.flush().ignore_timeout().into_diagnostic()?;
178181
}
179182
}
180183

181184
Ok(true)
182185
}
183186

187+
trait ErrorExt {
188+
fn ignore_timeout(self) -> Self;
189+
}
190+
191+
impl ErrorExt for Result<(), io::Error> {
192+
fn ignore_timeout(self) -> Self {
193+
match self {
194+
Ok(_) => Ok(()),
195+
Err(e) if e.kind() == ErrorKind::TimedOut => Ok(()),
196+
Err(e) => Err(e),
197+
}
198+
}
199+
}
200+
184201
fn key_event() -> std::io::Result<Option<KeyEvent>> {
185202
if !poll(Duration::ZERO)? {
186203
return Ok(None);

0 commit comments

Comments
 (0)