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

sync op result serialization errors result in panic and abort #14028

Closed
tim-palmer opened this issue Mar 18, 2022 · 0 comments · Fixed by #14033
Closed

sync op result serialization errors result in panic and abort #14028

tim-palmer opened this issue Mar 18, 2022 · 0 comments · Fixed by #14033

Comments

@tim-palmer
Copy link

If an error occurs in serde_v8 when converting the output of a sync op, it results in a panic and the process aborts.

The panic occurs because unwrap() is called on the result from serde_v8::to_v8. (The resulting panic then causes the whole process to abort, maybe due to denoland/rusty_v8#534.)

Example - this test results in "fatal runtime error: failed to initiate panic, error 5":

#[test]
fn test_serde_v8_error() {
  use serde::ser::{Serialize, Serializer};

  struct ErrOnSerialize;

  impl Serialize for ErrOnSerialize {
    fn serialize<S>(&self, _serializer: S) -> std::result::Result<S::Ok, S::Error> where S: Serializer {
      Err(serde::ser::Error::custom("always errors"))
    }
  }

  #[op]
  fn op_err() -> Result<ErrOnSerialize, anyhow::Error> {
    Ok(ErrOnSerialize)
  }

  run_in_task(|cx| {
    let ext = Extension::builder().ops(vec![op_err::decl()]).build();
    let mut runtime = JsRuntime::new(RuntimeOptions {
      extensions: vec![ext],
      ..Default::default()
    });
    runtime
      .execute_script(
        "test_serde_v8_error.js",
        "Deno.core.opSync('op_err')",
      )
      .unwrap();
    if let Poll::Ready(Err(_)) = runtime.poll_event_loop(cx, false) {
      unreachable!();
    }
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant