Add error message when file is not found

This commit is contained in:
imaqtkatt 2024-07-10 16:34:21 -03:00
parent 6bbc223048
commit 47f7cfd429
2 changed files with 12 additions and 2 deletions

View File

@ -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
@ -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

View File

@ -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(