Skip to content

Commit

Permalink
refactor(ext): align error messages (#25310)
Browse files Browse the repository at this point in the history
  • Loading branch information
irbull committed Sep 4, 2024
1 parent 1ec911f commit cb45435
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ext/cache/01_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Cache {
const reqUrl = new URL(innerRequest.url());
if (reqUrl.protocol !== "http:" && reqUrl.protocol !== "https:") {
throw new TypeError(
"Request url protocol must be 'http:' or 'https:'",
`Request url protocol must be 'http:' or 'https:': received '${reqUrl.protocol}'`,
);
}
if (innerRequest.method !== "GET") {
Expand Down
2 changes: 1 addition & 1 deletion ext/cache/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ where
state.put(cache);
Ok(state.borrow::<CA>().clone())
} else {
Err(type_error("CacheStorage is not available in this context."))
Err(type_error("CacheStorage is not available in this context"))
}
}

Expand Down
4 changes: 3 additions & 1 deletion ext/canvas/01_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ function processImage(input, width, height, sx, sy, sw, sh, options) {
}

if (options.colorSpaceConversion === "none") {
throw new TypeError("options.colorSpaceConversion 'none' is not supported");
throw new TypeError(
"Cannot create image: invalid colorSpaceConversion option, 'none' is not supported",
);
}

/*
Expand Down
12 changes: 7 additions & 5 deletions ext/ffi/00_ffi.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class UnsafePointer {
}
} else {
throw new TypeError(
"Expected ArrayBuffer, ArrayBufferView or UnsafeCallbackPrototype",
`Cannot access pointer: expected 'ArrayBuffer', 'ArrayBufferView' or 'UnsafeCallbackPrototype', received ${typeof value}`,
);
}
if (pointer) {
Expand Down Expand Up @@ -335,7 +335,9 @@ function getTypeSizeAndAlignment(type, cache = new SafeMap()) {
const cached = cache.get(type);
if (cached !== undefined) {
if (cached === null) {
throw new TypeError("Recursive struct definition");
throw new TypeError(
"Cannot get pointer size: found recursive struct",
);
}
return cached;
}
Expand Down Expand Up @@ -379,7 +381,7 @@ function getTypeSizeAndAlignment(type, cache = new SafeMap()) {
case "isize":
return [8, 8];
default:
throw new TypeError(`Unsupported type: ${type}`);
throw new TypeError(`Cannot get pointer size, unsupported type: ${type}`);
}
}

Expand All @@ -395,7 +397,7 @@ class UnsafeCallback {
constructor(definition, callback) {
if (definition.nonblocking) {
throw new TypeError(
"Invalid UnsafeCallback, cannot be nonblocking",
"Cannot construct UnsafeCallback: cannot be nonblocking",
);
}
const { 0: rid, 1: pointer } = op_ffi_unsafe_callback_create(
Expand Down Expand Up @@ -467,7 +469,7 @@ class DynamicLibrary {
const type = symbols[symbol].type;
if (type === "void") {
throw new TypeError(
"Foreign symbol of type 'void' is not supported.",
"Foreign symbol of type 'void' is not supported",
);
}

Expand Down
4 changes: 3 additions & 1 deletion ext/ffi/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ pub fn op_ffi_call_nonblocking(
let symbols = &resource.symbols;
*symbols
.get(&symbol)
.ok_or_else(|| type_error("Invalid FFI symbol name"))?
.ok_or_else(|| {
type_error(format!("Invalid FFI symbol name: '{symbol}'"))
})?
.clone()
};

Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ unsafe extern "C" fn deno_ffi_callback(
let tc_scope = &mut TryCatch::new(scope);
args.run(tc_scope);
if tc_scope.exception().is_some() {
log::error!("Illegal unhandled exception in nonblocking callback.");
log::error!("Illegal unhandled exception in nonblocking callback");
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ffi/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ fn ffi_callback_errors_test() {
assert_eq!(stdout, expected);
assert_eq!(
stderr,
"Illegal unhandled exception in nonblocking callback.\n".repeat(3)
"Illegal unhandled exception in nonblocking callback\n".repeat(3)
);
}

0 comments on commit cb45435

Please sign in to comment.