From d0c3adb318d314ff8f0ec7000d2ab8faf9485117 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 15 Oct 2024 09:00:48 +0200 Subject: [PATCH] use better error position for null_pos uncaught exceptions closes #11788 --- src/macro/eval/evalExceptions.ml | 9 ++++++++- .../projects/Issue10623/compile-fail.hxml.stderr | 3 +-- .../projects/Issue10623/indent-fail.hxml.stderr | 3 +-- .../projects/Issue10623/pretty-fail.hxml.stderr | 13 ++++--------- .../user-defined-define-json-fail.hxml.stderr | 3 +-- .../user-defined-meta-json-fail.hxml.stderr | 3 +-- .../user-defined-meta-json-indent-fail.hxml.stderr | 3 +-- .../projects/Issue11776/compile-fail.hxml.stderr | 3 +-- .../projects/Issue8303/compile-fail.hxml.stderr | 3 +-- .../misc/projects/Issue8303/indent-fail.hxml.stderr | 3 +-- .../misc/projects/Issue8303/pretty-fail.hxml.stderr | 6 +----- 11 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/macro/eval/evalExceptions.ml b/src/macro/eval/evalExceptions.ml index dd245852998..3c8a80c3bf3 100644 --- a/src/macro/eval/evalExceptions.ml +++ b/src/macro/eval/evalExceptions.ml @@ -184,7 +184,14 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p = let stack = get_stack ctx in reset_ctx(); final(); - let p = if p' = null_pos then p else p' in + let p,stack = match stack with + | p :: pl when p' = null_pos -> + (* If the exception position is null_pos we're probably in a built-in function. Let's use the topmost stack + as error position. *) + p,pl + | _ -> + (if p' = null_pos then p else p'),stack + in Error.raise_error (Error.make_error ~sub:(List.map (fun p -> Error.make_error (Error.Custom "Called from here") p) (List.rev stack)) (Error.Custom ("Uncaught exception " ^ (value_string v))) diff --git a/tests/misc/projects/Issue10623/compile-fail.hxml.stderr b/tests/misc/projects/Issue10623/compile-fail.hxml.stderr index 9d78f61833a..5c7fea41a10 100644 --- a/tests/misc/projects/Issue10623/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue10623/compile-fail.hxml.stderr @@ -1,2 +1 @@ -Uncaught exception Invalid string -Main.hx:5: characters 3-18 : Called from here \ No newline at end of file +Main.hx:5: characters 3-18 : Uncaught exception Invalid string \ No newline at end of file diff --git a/tests/misc/projects/Issue10623/indent-fail.hxml.stderr b/tests/misc/projects/Issue10623/indent-fail.hxml.stderr index 0e5c4ba4c84..5c7fea41a10 100644 --- a/tests/misc/projects/Issue10623/indent-fail.hxml.stderr +++ b/tests/misc/projects/Issue10623/indent-fail.hxml.stderr @@ -1,2 +1 @@ -Uncaught exception Invalid string - Main.hx:5: characters 3-18 : Called from here +Main.hx:5: characters 3-18 : Uncaught exception Invalid string \ No newline at end of file diff --git a/tests/misc/projects/Issue10623/pretty-fail.hxml.stderr b/tests/misc/projects/Issue10623/pretty-fail.hxml.stderr index f8ec7351f05..9b10f1e5512 100644 --- a/tests/misc/projects/Issue10623/pretty-fail.hxml.stderr +++ b/tests/misc/projects/Issue10623/pretty-fail.hxml.stderr @@ -1,10 +1,5 @@ -[ERROR] (unknown position) - - | Uncaught exception Invalid string - - -> Main.hx:5: characters 3-18 - - 5 | data.toString().substr(0); - | ^^^^^^^^^^^^^^^ - | Called from here +[ERROR] Main.hx:5: characters 3-18 + 5 | data.toString().substr(0); + | ^^^^^^^^^^^^^^^ + | Uncaught exception Invalid string \ No newline at end of file diff --git a/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr index 71888302865..7da58d1f7cb 100644 --- a/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr @@ -1,3 +1,2 @@ -(unknown) : Uncaught exception Could not read file define.jsno -$$normPath(::std::)/haxe/macro/Compiler.hx:401: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:401: characters 11-39 : Uncaught exception Could not read file define.jsno (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr index 9f77e04b2fb..d4f6b78b7ee 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr @@ -1,3 +1,2 @@ -(unknown) : Uncaught exception Could not read file meta.jsno -$$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 : Uncaught exception Could not read file meta.jsno (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr index 5a81672cb2a..0703acfda4a 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr @@ -1,3 +1,2 @@ -(unknown) : Uncaught exception Could not read file meta.jsno - $$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 : Uncaught exception Could not read file meta.jsno (unknown) : Called from here diff --git a/tests/misc/projects/Issue11776/compile-fail.hxml.stderr b/tests/misc/projects/Issue11776/compile-fail.hxml.stderr index c9d6764cd7c..d0be6277cf5 100644 --- a/tests/misc/projects/Issue11776/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue11776/compile-fail.hxml.stderr @@ -1,3 +1,2 @@ -Main.hx:3: characters 3-20 : Uncaught exception Could not find macro function "oh no" -Main.hx:7: characters 3-40 : Called from here +Main.hx:7: characters 3-40 : Uncaught exception Could not find macro function "oh no" Main.hx:3: characters 3-20 : Called from here \ No newline at end of file diff --git a/tests/misc/projects/Issue8303/compile-fail.hxml.stderr b/tests/misc/projects/Issue8303/compile-fail.hxml.stderr index 00dd0661cfb..bbf2aa04132 100644 --- a/tests/misc/projects/Issue8303/compile-fail.hxml.stderr +++ b/tests/misc/projects/Issue8303/compile-fail.hxml.stderr @@ -1,5 +1,4 @@ -Uncaught exception Stack overflow -Main.hx:1: character 1 : Called from here +Main.hx:1: character 1 : Uncaught exception Stack overflow Main.hx:8: characters 4-9 : Called from here Main.hx:8: characters 4-9 : Called from here Main.hx:8: characters 4-9 : Called from here diff --git a/tests/misc/projects/Issue8303/indent-fail.hxml.stderr b/tests/misc/projects/Issue8303/indent-fail.hxml.stderr index 85bcacbd35d..e90cbbf56ec 100644 --- a/tests/misc/projects/Issue8303/indent-fail.hxml.stderr +++ b/tests/misc/projects/Issue8303/indent-fail.hxml.stderr @@ -1,5 +1,4 @@ -Uncaught exception Stack overflow - Main.hx:1: character 1 : Called from here +Main.hx:1: character 1 : Uncaught exception Stack overflow Main.hx:8: characters 4-9 : Called from here Main.hx:8: characters 4-9 : Called from here Main.hx:8: characters 4-9 : Called from here diff --git a/tests/misc/projects/Issue8303/pretty-fail.hxml.stderr b/tests/misc/projects/Issue8303/pretty-fail.hxml.stderr index 2cd268477fb..54ca16e1343 100644 --- a/tests/misc/projects/Issue8303/pretty-fail.hxml.stderr +++ b/tests/misc/projects/Issue8303/pretty-fail.hxml.stderr @@ -1,11 +1,7 @@ -[ERROR] (unknown position) +[ERROR] Main.hx | Uncaught exception Stack overflow - -> Main.hx - - | Called from here - 8 | log(); | ^^^^^ | Called from here