Browse Source

[pretty errors] don't break if source file doesn't exist (#11119)

Rudy Ges 2 years ago
parent
commit
9786c26fae

+ 8 - 9
src/compiler/server.ml

@@ -179,18 +179,16 @@ module Communication = struct
 				if is_null_pos then begin
 					let epos = if is_unknown_file cm.cm_pos.pfile then "(unknown position)" else cm.cm_pos.pfile in
 					(-1, -1, -1, -1, epos, [])
-				end else begin
+				end else try begin
 					let f = resolve_file ctx.com cm.cm_pos.pfile in
-					let f =
-						try Common.find_file ctx.com f
-						with Not_found -> failwith ("File not found '" ^ cm.cm_pos.pfile ^ "'")
-						in
-
+					let f = Common.find_file ctx.com f in
 					let l1, p1, l2, p2 = Lexer.get_pos_coords cm.cm_pos in
 					let lines = resolve_source f l1 p1 l2 p2 in
 					let epos = Lexer.get_error_pos error_printer cm.cm_pos in
 					(l1, p1, l2, p2, epos, lines)
-				end in
+				end with Not_found ->
+					(1, 1, 1, 1, cm.cm_pos.pfile, [])
+				in
 
 			(* If 4 lines or less, display all; if more, crop the middle *)
 			let lines = match lines with
@@ -227,8 +225,9 @@ module Communication = struct
 			) in
 
 			let display_heading = cm.cm_depth = 0 || sev_changed || file_changed in
-			let display_source = cm.cm_depth = 0 || sev_changed || pos_changed in
-			let display_pos_marker = (not is_null_pos) && (cm.cm_depth = 0 || sev_changed || pos_changed) in
+			let has_source = match lines with | [] -> false | _ -> true in
+			let display_source = has_source && (cm.cm_depth = 0 || sev_changed || pos_changed) in
+			let display_pos_marker = (not is_null_pos) && has_source && (cm.cm_depth = 0 || sev_changed || pos_changed) in
 
 			let gutter_len = (try String.length (Printf.sprintf "%d" (IntMap.find cm.cm_depth ectx.max_lines)) with Not_found -> 0) + 2 in
 

+ 3 - 0
tests/misc/java/projects/Issue11095/pretty-fail.hxml

@@ -0,0 +1,3 @@
+compile-fail.hxml
+-D message-reporting=pretty
+-D no-color

+ 4 - 0
tests/misc/java/projects/Issue11095/pretty-fail.hxml.stderr

@@ -0,0 +1,4 @@
+[ERROR] no-rudy.jar@haxe/root/NoRudy.class
+
+   | Should extend by using a class, found TAbstract(Rudy, [])
+