Skip to content

Commit

Permalink
fix: getFileName can return null (#861)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek authored Aug 5, 2024
1 parent c818185 commit 3ccced1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,10 @@ pub mod callsite_fns {
};
// call getFileName
let orig_ret =
call_method::<v8::String>(scope, orig, super::GET_FILE_NAME, &[]);
if let Some(ret_val) = orig_ret {
call_method::<v8::Value>(scope, orig, super::GET_FILE_NAME, &[]);
if let Some(ret_val) =
orig_ret.and_then(|v| v.try_cast::<v8::String>().ok())
{
// strip off `file://`
let string = ret_val.to_rust_string_lossy(scope);
if let Some(file_name) = maybe_to_path_str(&string) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions testing/integration/error_get_file_name/error_get_file_name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

// deno-lint-ignore no-explicit-any
(Error as any).prepareStackTrace = (_err: unknown, frames: any[]) => {
return frames.map((frame) => frame.getFileName());
};

new Promise((_, reject) => {
reject(new Error("fail").stack);
}).catch((err) => {
console.log(err);
});
1 change: 1 addition & 0 deletions testing/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ integration_test!(
error_prepare_stack_trace,
error_with_stack,
error_without_stack,
error_get_file_name,
main_module_handler,
module_types,
pending_unref_op_tla,
Expand Down

0 comments on commit 3ccced1

Please sign in to comment.