Skip to content

Commit

Permalink
use better error position for null_pos uncaught exceptions
Browse files Browse the repository at this point in the history
closes #11788
  • Loading branch information
Simn committed Oct 15, 2024
1 parent 9aa9911 commit d0c3adb
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 31 deletions.
9 changes: 8 additions & 1 deletion src/macro/eval/evalExceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue10623/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue10623/indent-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
13 changes: 4 additions & 9 deletions tests/misc/projects/Issue10623/pretty-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue11776/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue8303/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/misc/projects/Issue8303/indent-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/misc/projects/Issue8303/pretty-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[ERROR] (unknown position)
[ERROR] Main.hx

| Uncaught exception Stack overflow

-> Main.hx

| Called from here

8 | log();
| ^^^^^
| Called from here
Expand Down

0 comments on commit d0c3adb

Please sign in to comment.