Browse Source

use better error position for null_pos uncaught exceptions

closes #11788
Simon Krajewski 9 months ago
parent
commit
d0c3adb318

+ 8 - 1
src/macro/eval/evalExceptions.ml

@@ -184,7 +184,14 @@ let catch_exceptions ctx ?(final=(fun() -> ())) f p =
 			let stack = get_stack ctx in
 			let stack = get_stack ctx in
 			reset_ctx();
 			reset_ctx();
 			final();
 			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
 			Error.raise_error (Error.make_error
 				~sub:(List.map (fun p -> Error.make_error (Error.Custom "Called from here") p) (List.rev stack))
 				~sub:(List.map (fun p -> Error.make_error (Error.Custom "Called from here") p) (List.rev stack))
 				(Error.Custom ("Uncaught exception " ^ (value_string v)))
 				(Error.Custom ("Uncaught exception " ^ (value_string v)))

+ 1 - 2
tests/misc/projects/Issue10623/compile-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

+ 1 - 2
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

+ 4 - 9
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

+ 1 - 2
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
 (unknown) : Called from here

+ 1 - 2
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
 (unknown) : Called from here

+ 1 - 2
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
   (unknown) : Called from here

+ 1 - 2
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
 Main.hx:3: characters 3-20 : Called from here

+ 1 - 2
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
 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

+ 1 - 2
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
   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

+ 1 - 5
tests/misc/projects/Issue8303/pretty-fail.hxml.stderr

@@ -1,11 +1,7 @@
-[ERROR] (unknown position)
+[ERROR] Main.hx
 
 
    | Uncaught exception Stack overflow
    | Uncaught exception Stack overflow
 
 
-    ->  Main.hx
-
-       | Called from here
-
      8 |    log();
      8 |    log();
        |    ^^^^^
        |    ^^^^^
        | Called from here
        | Called from here