Skip to content

Commit

Permalink
Fix consistency check when env variable is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Aug 9, 2024
1 parent 003c2a0 commit 869c8e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixed

- Write the log tree on the error "lexical scope of close_log not matching its dynamic scope", so the entries from the error message can be looked up.
- Uncaught exception in the `[%%global_debug_log_level_from_env_var "..."]` consistency check when the environment variable is not defined.

## [1.6.0] -- 2024-08-08

Expand Down
31 changes: 18 additions & 13 deletions ppx_minidebug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1535,19 +1535,24 @@ let global_log_level_from_env_var ~check_consistency =
in
A.pstr_eval ~loc
[%expr
let runtime_log_level =
Stdlib.String.lowercase_ascii
@@ Stdlib.Sys.getenv
[%e
Ast_helper.Exp.constant ~loc:s_loc
@@ Ast_helper.Const.string ~loc:s_loc env_n]
in
if not (Stdlib.String.equal [%e lifted_log_level] runtime_log_level)
then
failwith
("ppx_minidebug: compile-time vs. runtime log level mismatch, \
found '" ^ [%e lifted_log_level] ^ "' at compile time, '"
^ runtime_log_level ^ "' at runtime")]
try
let runtime_log_level =
Stdlib.String.lowercase_ascii
@@ Stdlib.Sys.getenv
[%e
Ast_helper.Exp.constant ~loc:s_loc
@@ Ast_helper.Const.string ~loc:s_loc env_n]
in
if
(not (Stdlib.String.equal "" runtime_log_level))
&& not
(Stdlib.String.equal [%e lifted_log_level] runtime_log_level)
then
failwith
("ppx_minidebug: compile-time vs. runtime log level mismatch, \
found '" ^ [%e lifted_log_level] ^ "' at compile time, '"
^ runtime_log_level ^ "' at runtime")
with Stdlib.Not_found -> ()]
attrs
else noop
in
Expand Down

0 comments on commit 869c8e9

Please sign in to comment.