summaryrefslogtreecommitdiff
path: root/core/ops_json.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2021-04-09 16:55:33 +0100
committerGitHub <noreply@github.com>2021-04-09 11:55:33 -0400
commitc86ee742a2522a169bfe40890b946c646aeac1cf (patch)
tree73b6f1efb0a72ab9f8186d76595186b133b4b554 /core/ops_json.rs
parentc6e7a243d524417fe77c4799a2bcc1b3db1bf01a (diff)
fix: async op error stacktraces (#10080)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'core/ops_json.rs')
-rw-r--r--core/ops_json.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/core/ops_json.rs b/core/ops_json.rs
index 21c6b219f..0efd44a90 100644
--- a/core/ops_json.rs
+++ b/core/ops_json.rs
@@ -108,3 +108,51 @@ where
},
)
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[tokio::test]
+ async fn json_op_async_stack_trace() {
+ let mut runtime = crate::JsRuntime::new(Default::default());
+
+ async fn op_throw(
+ _state: Rc<RefCell<OpState>>,
+ msg: Option<String>,
+ zero_copy: Option<ZeroCopyBuf>,
+ ) -> Result<(), AnyError> {
+ assert_eq!(msg.unwrap(), "hello");
+ assert!(zero_copy.is_none());
+ Err(crate::error::generic_error("foo"))
+ }
+
+ runtime.register_op("op_throw", json_op_async(op_throw));
+ runtime
+ .execute(
+ "<init>",
+ r#"
+ // First we initialize the ops cache. This maps op names to their id's.
+ Deno.core.ops();
+ // Register the error class.
+ Deno.core.registerErrorClass('Error', Error);
+
+ async function f1() {
+ await Deno.core.jsonOpAsync('op_throw', 'hello');
+ }
+
+ async function f2() {
+ await f1();
+ }
+
+ f2();
+ "#,
+ )
+ .unwrap();
+ let e = runtime.run_event_loop().await.unwrap_err().to_string();
+ println!("{}", e);
+ assert!(e.contains("Error: foo"));
+ assert!(e.contains("at async f1 (<init>:"));
+ assert!(e.contains("at async f2 (<init>:"));
+ }
+}