Skip to content

Prevent trying to read non-existing file when extracting extra info for error messages #7656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- Rewatch: Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
- Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648
- Fix inside comment printing for empty dict. https://github.com/rescript-lang/rescript/pull/7654
- Fix I/O error message when trying to extract extra info from non-existing file. https://github.com/rescript-lang/rescript/pull/7656

# 12.0.0-beta.1

Expand Down
10 changes: 7 additions & 3 deletions compiler/ml/error_message_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ end = struct
String.sub src start_offset (end_offset - start_offset)

let extract_text_at_loc loc =
(* TODO: Maybe cache later on *)
let src = Ext_io.load_file loc.Location.loc_start.pos_fname in
extract_location_string ~src loc
if loc.Location.loc_start.pos_fname = "_none_" then ""
else
try
(* TODO: Maybe cache later on *)
let src = Ext_io.load_file loc.Location.loc_start.pos_fname in
extract_location_string ~src loc
with _ -> ""

let parse_expr_at_loc loc =
let sub_src = extract_text_at_loc loc in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

We've found a bug for you!
/.../fixtures/extract_from_none_file.res

This has type: RegExp.t
But a while loop condition must always be of type: bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This will try and extract the text from a non-existing file.
// Test is intended to check that this does not crash.
while /foo/ {
()
}