Skip to content

Commit

Permalink
Catch missing standard library in init macros
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Mar 29, 2024
1 parent cbb8d6e commit 0fc3700
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/core/error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ let raise_msg ?(depth = 0) msg p = raise_error_msg ~depth (Custom msg) p
let raise_typing_error ?(depth = 0) msg p = raise_msg ~depth msg p
let raise_typing_error_ext err = raise_error err

let raise_std_not_found () =
try
let std_path = Sys.getenv "HAXE_STD_PATH" in
raise_typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
with Not_found ->
raise_typing_error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos

let error_require r p =
if r = "" then
raise_typing_error "This field is not available with the current compilation flags" p
Expand Down
5 changes: 4 additions & 1 deletion src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,10 @@ let create_macro_context com =
[cp#clone]
) com.class_paths#as_list;
(* Eval _std must be in front so we don't look into hxnodejs or something. *)
com2.class_paths#add (Option.get !eval_std);
(* This can run before `TyperEntry.create`, so in order to display nice error when std is not found, this needs to be checked here too *)
(match !eval_std with
| Some std -> com2.class_paths#add std
| None -> Error.raise_std_not_found ());
let defines = adapt_defines_to_macro_context com2.defines; in
com2.defines.values <- defines.values;
com2.defines.defines_signature <- None;
Expand Down
6 changes: 1 addition & 5 deletions src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ let create com macros =
TypeloadModule.load_module ctx ([],"StdTypes") null_pos
with
Error { err_message = Module_not_found ([],"StdTypes") } ->
try
let std_path = Sys.getenv "HAXE_STD_PATH" in
raise_typing_error ("Standard library not found. Please check your `HAXE_STD_PATH` environment variable (current value: \"" ^ std_path ^ "\")") null_pos
with Not_found ->
raise_typing_error "Standard library not found. You may need to set your `HAXE_STD_PATH` environment variable" null_pos
Error.raise_std_not_found ()
);
(* We always want core types to be available so we add them as default imports (issue #1904 and #3131). *)
List.iter (fun mt ->
Expand Down

0 comments on commit 0fc3700

Please sign in to comment.