0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix(core): improve error on invalid op id (#13056)

This commit is contained in:
Bartek Iwańczuk 2021-12-12 17:11:41 +01:00 committed by GitHub
parent 83804f7c99
commit 34f05f673e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}
};