Skip to content

Commit

Permalink
[hxb] Display compiler failure when failing write_full_path
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Apr 3, 2024
1 parent aefa949 commit d283959
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/compiler/hxb/hxbReader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()

Expand Down
15 changes: 14 additions & 1 deletion src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d283959

Please sign in to comment.