@@ -4,26 +4,62 @@ use common::errors::{
44 FrameData ,
55 JsError ,
66} ;
7+ use deno_core:: v8;
78
89use super :: OpProvider ;
9- use crate :: environment:: UncatchableDeveloperError ;
10+ use crate :: {
11+ environment:: UncatchableDeveloperError ,
12+ strings,
13+ } ;
1014
11- #[ convex_macro:: v8_op]
12- pub fn op_throw_uncatchable_developer_error < ' b , P : OpProvider < ' b > > (
15+ pub ( crate ) fn throw_uncatchable_developer_error < ' b , P : OpProvider < ' b > > (
1316 provider : & mut P ,
1417 message : String ,
15- frame_data : Vec < FrameData > ,
16- ) -> anyhow:: Result < ( ) > {
17- let js_error = JsError :: from_frames ( message. clone ( ) , frame_data, None , |s| {
18- provider. lookup_source_map ( s)
19- } ) ;
18+ ) -> anyhow:: Result < !> {
19+ let frame_data: anyhow:: Result < Vec < FrameData > > = try {
20+ let mut scope = v8:: HandleScope :: new ( provider. scope ( ) ) ;
21+ let empty_string = strings:: empty. create ( & mut scope) ?;
22+ let error = v8:: Exception :: error ( & mut scope, empty_string) . try_cast :: < v8:: Object > ( ) ?;
23+ let stack_string = strings:: stack. create ( & mut scope) ?;
24+ // This calls `prepareStackTrace` that populates `__frameData`
25+ error
26+ . get ( & mut scope, stack_string. into ( ) )
27+ . context ( "Error.stack threw" ) ?;
28+ let frame_data_str = strings:: __frameData. create ( & mut scope) ?;
29+ let frame_data_json = error
30+ . get ( & mut scope, frame_data_str. into ( ) )
31+ . context ( "Error.__frameData threw" ) ?
32+ . try_cast :: < v8:: String > ( ) ?;
33+ let frame_data_json = frame_data_json. to_rust_string_lossy ( & mut scope) ;
34+ serde_json:: from_str ( & frame_data_json) ?
35+ } ;
36+ let js_error = JsError :: from_frames (
37+ message. clone ( ) ,
38+ match frame_data {
39+ Ok ( data) => data,
40+ Err ( mut e) => {
41+ report_error_sync ( & mut e) ;
42+ vec ! [ ]
43+ } ,
44+ } ,
45+ None ,
46+ |s| provider. lookup_source_map ( s) ,
47+ ) ;
2048 report_error_sync ( & mut anyhow:: anyhow!( format!(
2149 "UncatchableDeveloperError: {}" ,
2250 message
2351 ) ) ) ;
2452 anyhow:: bail!( UncatchableDeveloperError { js_error } )
2553}
2654
55+ #[ convex_macro:: v8_op]
56+ pub fn op_throw_uncatchable_developer_error < ' b , P : OpProvider < ' b > > (
57+ provider : & mut P ,
58+ message : String ,
59+ ) -> anyhow:: Result < ( ) > {
60+ throw_uncatchable_developer_error ( provider, message) ?;
61+ }
62+
2763/// Do source mapping to find the stack trace for an error.
2864/// NOTE if a UDF throws an error, we call this op and then separately do
2965/// source mapping again so the yielded error has structured frame data.
0 commit comments