Przeglądaj źródła

[hxb] Display compiler failure when failing write_full_path

Rudy Ges 1 rok temu
rodzic
commit
d283959f8f
2 zmienionych plików z 20 dodań i 4 usunięć
  1. 6 3
      src/compiler/hxb/hxbReader.ml
  2. 14 1
      src/compiler/hxb/hxbWriter.ml

+ 6 - 3
src/compiler/hxb/hxbReader.ml

@@ -1973,13 +1973,16 @@ class hxb_reader
 		| EOM ->
 			incr stats.modules_fully_restored;
 
-	method private die chunk msg =
+	method private get_backtrace () = Printexc.get_raw_backtrace ()
+	method private get_callstack () = Printexc.get_callstack 200
+
+	method private failwith chunk msg backtrace =
 		let msg =
 			(Printf.sprintf "Compiler failure while reading hxb chunk %s of %s: %s\n" (string_of_chunk_kind chunk) (s_type_path mpath) (msg))
 			^ "Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new\n"
 			^ "Attach the following information:"
 		in
-		let backtrace = Printexc.raw_backtrace_to_string (Printexc.get_raw_backtrace ()) in
+		let backtrace = Printexc.raw_backtrace_to_string backtrace in
 		let s = Printf.sprintf "%s\nHaxe: %s\n%s" msg s_version_full backtrace in
 		failwith s
 
@@ -1991,7 +1994,7 @@ class hxb_reader
 			self#read_chunk_data' kind
 		with Invalid_argument msg -> begin
 			close();
-			self#die kind msg
+			self#failwith kind msg (self#get_backtrace ())
 		end;
 		close()
 

+ 14 - 1
src/compiler/hxb/hxbWriter.ml

@@ -475,6 +475,19 @@ type hxb_writer = {
 }
 
 module HxbWriter = struct
+	let get_backtrace () = Printexc.get_raw_backtrace ()
+	let get_callstack () = Printexc.get_callstack 200
+
+	let failwith writer msg backtrace =
+		let msg =
+			(Printf.sprintf "Compiler failure while writing hxb chunk %s of %s: %s\n" (string_of_chunk_kind writer.chunk.kind) (s_type_path writer.current_module.m_path) (msg))
+			^ "Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new\n"
+			^ "Attach the following information:"
+		in
+		let backtrace = Printexc.raw_backtrace_to_string backtrace in
+		let s = Printf.sprintf "%s\nHaxe: %s\n%s" msg s_version_full backtrace in
+		failwith s
+
 	let in_nested_scope writer = match writer.field_stack with
 		| [] -> false (* can happen for cl_init and in EXD *)
 		| [_] -> false
@@ -528,7 +541,7 @@ module HxbWriter = struct
 	let write_full_path writer (pack : string list) (mname : string) (tname : string) =
 		Chunk.write_list writer.chunk pack (Chunk.write_string writer.chunk);
 		if mname = "" || tname = "" then
-			die (Printf.sprintf "write_full_path: pack = %s, mname = %s, tname = %s" (String.concat "." pack) mname tname) __LOC__;
+			failwith writer (Printf.sprintf "write_full_path: pack = %s, mname = %s, tname = %s" (String.concat "." pack) mname tname) (get_callstack ());
 		Chunk.write_string writer.chunk mname;
 		Chunk.write_string writer.chunk tname