Skip to content

Commit e6e2bf5

Browse files
committed
Don't mangle escapes in Error::Timeout
This was added in 1a32fbc, for unclear reasons. They say "for easier debugging", but e.g. the `Error::EOF` variant wasn't given the same treatment. Also, if you do a `session.exp_string("...").unwrap()`, you get terribly mangled output that misrepresents what the program actually printed, e.g.: ``` called `Result::unwrap()` on an `Err` value: Timeout { expected: "\"Hello, world!\"", got: "\u{8}`^`[2C`^`[?7h`^`[0m`^} ``` Instead, we should use a familiar and predictable escaping format: the built-in `impl Debug for String`.
1 parent 3706084 commit e6e2bf5

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time;
22

33
#[derive(Debug, thiserror::Error)]
44
pub enum Error {
5-
#[error("EOF (End of File): Expected {} but got EOF after reading \"{}\" process terminated with {:?}", .expected, .got, .exit_code.as_ref().unwrap_or(&"unknown".to_owned()))]
5+
#[error("EOF (End of File): Expected {:?} but got EOF after reading {:?} process terminated with {:?}", .expected, .got, .exit_code.as_ref().unwrap_or(&"unknown".to_owned()))]
66
EOF {
77
expected: String,
88
got: String,
@@ -12,7 +12,7 @@ pub enum Error {
1212
#[error("PipeError")]
1313
BrokenPipe,
1414

15-
#[error("Timeout Error: Expected {} but got \"{}\" (after waiting {} ms)", .expected, .got, (.timeout.as_secs() * 1000) as u32 + .timeout.subsec_millis())]
15+
#[error("Timeout Error: Expected {:?} but got {:?} (after waiting {} ms)", .expected, .got, (.timeout.as_secs() * 1000) as u32 + .timeout.subsec_millis())]
1616
Timeout {
1717
expected: String,
1818
got: String,

src/reader.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,7 @@ impl NBReader {
273273
if start.elapsed() > timeout {
274274
return Err(Error::Timeout {
275275
expected: needle.to_string(),
276-
got: self
277-
.buffer
278-
.clone()
279-
.replace('\n', "`\\n`\n")
280-
.replace('\r', "`\\r`")
281-
.replace('\u{1b}', "`^`"),
276+
got: self.buffer.clone(),
282277
timeout,
283278
});
284279
}

0 commit comments

Comments
 (0)