Skip to content

Commit

Permalink
Merge pull request #628 from HigherOrderCO/513-improve-error-message-…
Browse files Browse the repository at this point in the history
…when-the-input-file-is-not-found

#513 Improve error message when the input file is not found
  • Loading branch information
imaqtkatt authored Jul 11, 2024
2 parents 6bbc223 + 2f8062b commit e239264
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project does not currently adhere to a particular versioning scheme.

- Add import system. ([#544][gh-544])
- Add multi line comment `#{ ... #}` syntax. ([#595][gh-595])
- Add error message when input file is not found. ([#513][gh-513])

## [0.2.36] - 2024-07-04

Expand Down Expand Up @@ -372,6 +373,7 @@ and this project does not currently adhere to a particular versioning scheme.
[gh-494]: https://github.com/HigherOrderCO/Bend/issues/494
[gh-502]: https://github.com/HigherOrderCO/Bend/issues/502
[gh-512]: https://github.com/HigherOrderCO/Bend/issues/512
[gh-513]: https://github.com/HigherOrderCO/Bend/issues/513
[gh-514]: https://github.com/HigherOrderCO/Bend/issues/514
[gh-516]: https://github.com/HigherOrderCO/Bend/issues/516
[gh-526]: https://github.com/HigherOrderCO/Bend/issues/526
Expand Down
12 changes: 10 additions & 2 deletions src/fun/load_book.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ pub fn load_file_to_book(
package_loader: impl PackageLoader,
diag: DiagnosticsConfig,
) -> Result<Book, Diagnostics> {
let code = std::fs::read_to_string(path).map_err(|e| e.to_string())?;
load_to_book(path, &code, package_loader, diag)
match path.try_exists() {
Ok(exists) => {
if !exists {
return Err(format!("The file '{}' was not found.", path.display()).into());
}
let code = std::fs::read_to_string(path).map_err(|e| e.to_string())?;
load_to_book(path, &code, package_loader, diag)
}
Err(e) => Err(e.to_string().into()),
}
}

pub fn load_to_book(
Expand Down
2 changes: 2 additions & 0 deletions tests/golden_tests/cli/input_file_not_found.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run
tests/golden_tests/missing_dir/input_file_not_found.bend
Empty file.
6 changes: 6 additions & 0 deletions tests/snapshots/cli__input_file_not_found.bend.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
source: tests/golden_tests.rs
input_file: tests/golden_tests/cli/input_file_not_found.bend
---
Errors:
The file 'tests/golden_tests/missing_dir/input_file_not_found.bend' was not found.

0 comments on commit e239264

Please sign in to comment.