diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-12-12 17:11:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 17:11:41 +0100 |
commit | 34f05f673e78c8ba2f275eb160fb5b6b21fa302a (patch) | |
tree | 32cdd28515df8301af28d1056dfd336dd1ef25ca | |
parent | 83804f7c9913ca139dec688f1e5bb9f5fa4e500e (diff) |
fix(core): improve error on invalid op id (#13056)
-rw-r--r-- | core/bindings.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/core/bindings.rs b/core/bindings.rs index 08075e9d5..06791b248 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -26,6 +26,11 @@ use v8::SharedArrayBuffer; use v8::ValueDeserializerHelper; use v8::ValueSerializerHelper; +const UNDEFINED_OP_ID_MSG: &str = + "invalid op id: received `undefined` instead of an integer. +This error is often caused by a typo in an op name, or not calling +JsRuntime::sync_ops_cache() after JsRuntime initialization."; + lazy_static::lazy_static! { pub static ref EXTERNAL_REFERENCES: v8::ExternalReferences = v8::ExternalReferences::new(&[ @@ -437,7 +442,12 @@ fn opcall_sync<'s>( { Ok(op_id) => op_id, Err(err) => { - throw_type_error(scope, format!("invalid op id: {}", err)); + let msg = if args.get(0).is_undefined() { + UNDEFINED_OP_ID_MSG.to_string() + } else { + format!("invalid op id: {}", err) + }; + throw_type_error(scope, msg); return; } }; @@ -494,7 +504,12 @@ fn opcall_async<'s>( { Ok(op_id) => op_id, Err(err) => { - throw_type_error(scope, format!("invalid op id: {}", err)); + let msg = if args.get(0).is_undefined() { + UNDEFINED_OP_ID_MSG.to_string() + } else { + format!("invalid op id: {}", err) + }; + throw_type_error(scope, msg); return; } }; |