File tree 2 files changed +34
-14
lines changed
itest/rust/src/object_tests
2 files changed +34
-14
lines changed Original file line number Diff line number Diff line change @@ -387,27 +387,39 @@ where
387
387
// Handle panic info only in Debug mode.
388
388
#[ cfg( debug_assertions) ]
389
389
{
390
- let guard = info. lock ( ) . unwrap ( ) ;
391
- let info = guard. as_ref ( ) . expect ( "no panic info available" ) ;
390
+ let msg = extract_panic_message ( err) ;
391
+ let mut msg = format_panic_message ( msg) ;
392
+
393
+ // try to add location information
394
+ if let Ok ( guard) = info. lock ( ) {
395
+ if let Some ( info) = guard. as_ref ( ) {
396
+ msg = format ! ( "{}\n at {}:{}" , msg, info. file, info. line) ;
397
+ }
398
+ }
399
+
392
400
if print {
393
401
godot_error ! (
394
- "Rust function panicked at {}:{}.\n Context: {}" ,
395
- info. file,
396
- info. line,
402
+ "Rust function panicked: {}\n Context: {}" ,
403
+ msg,
397
404
error_context( )
398
405
) ;
399
406
//eprintln!("Backtrace:\n{}", info.backtrace);
400
407
}
408
+
409
+ Err ( msg)
401
410
}
402
411
403
- let msg = extract_panic_message ( err) ;
404
- let msg = format_panic_message ( msg) ;
412
+ #[ cfg( not( debug_assertions) ) ]
413
+ {
414
+ let msg = extract_panic_message ( err) ;
415
+ let msg = format_panic_message ( msg) ;
416
+
417
+ if print {
418
+ godot_error ! ( "{msg}" ) ;
419
+ }
405
420
406
- if print {
407
- godot_error ! ( "{msg}" ) ;
421
+ Err ( msg)
408
422
}
409
-
410
- Err ( msg)
411
423
}
412
424
}
413
425
}
Original file line number Diff line number Diff line change @@ -148,13 +148,21 @@ fn dynamic_call_with_panic() {
148
148
149
149
assert_eq ! ( call_error. class_name( ) , Some ( "Object" ) ) ;
150
150
assert_eq ! ( call_error. method_name( ) , "call" ) ;
151
- assert_eq ! (
152
- call_error. to_string( ) ,
151
+
152
+ #[ cfg( target_os = "windows" ) ]
153
+ let path = "itest\\ rust\\ src\\ object_tests\\ object_test.rs" ;
154
+ #[ cfg( not( target_os = "windows" ) ) ]
155
+ let path = "itest/rust/src/object_tests/object_test.rs" ;
156
+
157
+ let expected_error_message = format ! (
153
158
"godot-rust function call failed: Object::call(&\" do_panic\" )\
154
159
\n Source: ObjPayload::do_panic()\
155
- \n Reason: [panic] do_panic exploded"
160
+ \n Reason: [panic] do_panic exploded\
161
+ \n at {path}:893"
156
162
) ;
157
163
164
+ assert_eq ! ( call_error. to_string( ) , expected_error_message) ;
165
+
158
166
obj. free ( ) ;
159
167
}
160
168
You can’t perform that action at this time.
0 commit comments