Skip to content

Commit

Permalink
Use string for RunnerError instead of byte vector (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles authored Nov 6, 2024
1 parent 2076f15 commit 6daa25b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/cli/tests/dylib_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_dylib_with_error() -> Result<()> {
let expected_log_output = "Error:1:24 foo error\n at foo (function.mjs:1:24)\n at <anonymous> (function.mjs:1:50)\n\n";
assert_eq!(
expected_log_output,
String::from_utf8(e.downcast_ref::<RunnerError>().unwrap().stderr.clone())?
e.downcast_ref::<RunnerError>().unwrap().stderr
);

Ok(())
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ fn test_promises(builder: &mut Builder) -> Result<()> {
let mut runner = builder.input("promise.js").build()?;
let res = runner.exec(&[]);
let err = res.err().unwrap().downcast::<RunnerError>().unwrap();
assert!(str::from_utf8(&err.stderr)
.unwrap()
.contains("Pending jobs in the event queue."));
assert!(err.stderr.contains("Pending jobs in the event queue."));

Ok(())
}
Expand Down Expand Up @@ -272,7 +270,7 @@ fn test_error_handling(builder: &mut Builder) -> Result<()> {

let expected_log_output = "Error:2:9 error\n at error (function.mjs:2:9)\n at <anonymous> (function.mjs:5:1)\n\n";

assert_eq!(expected_log_output, str::from_utf8(&err.stderr).unwrap());
assert_eq!(expected_log_output, err.stderr);
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions crates/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub struct Runner {
#[derive(Debug)]
pub struct RunnerError {
pub stdout: Vec<u8>,
pub stderr: Vec<u8>,
pub stderr: String,
pub err: anyhow::Error,
}

Expand All @@ -234,7 +234,7 @@ impl Display for RunnerError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"error: {:?}, stdout: {:?}, stderr: {:?}",
"error: {:?}, stdout: {:?}, stderr: {}",
self.err, self.stdout, self.stderr
)
}
Expand Down Expand Up @@ -809,7 +809,7 @@ impl Runner {
Ok(_) => Ok((output, logs, fuel_consumed)),
Err(err) => Err(RunnerError {
stdout: output,
stderr: logs,
stderr: String::from_utf8(logs).unwrap(),
err,
}
.into()),
Expand Down

0 comments on commit 6daa25b

Please sign in to comment.