Skip to content

Commit 80dd35c

Browse files
committed
prevent trying to read non-existing file when extracting extra info for error messages
1 parent 2c96b79 commit 80dd35c

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

compiler/ml/error_message_utils.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ end = struct
4141
String.sub src start_offset (end_offset - start_offset)
4242

4343
let extract_text_at_loc loc =
44-
(* TODO: Maybe cache later on *)
45-
let src = Ext_io.load_file loc.Location.loc_start.pos_fname in
46-
extract_location_string ~src loc
44+
if loc.Location.loc_start.pos_fname = "_none_" then ""
45+
else
46+
try
47+
(* TODO: Maybe cache later on *)
48+
let src = Ext_io.load_file loc.Location.loc_start.pos_fname in
49+
extract_location_string ~src loc
50+
with _ -> ""
4751

4852
let parse_expr_at_loc loc =
4953
let sub_src = extract_text_at_loc loc in
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/extract_from_none_file.res
4+
5+
This has type: RegExp.t
6+
But a while loop condition must always be of type: bool
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This will try and extract the text from a non-existing file.
2+
// Test is intended to check that this does not crash.
3+
while /foo/ {
4+
()
5+
}

0 commit comments

Comments
 (0)