diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-06-14 20:07:27 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-06-14 20:07:27 +0200 |
| commit | 7fb19d5ef8dc3b183d7de811e373768de56f7ee8 (patch) | |
| tree | 885a94958e8270615aa57069b4d07db82e534b2c /src/diag.rs | |
| parent | 0dacb2d151e1790613b324b3051b8ce7aa26a90e (diff) | |
Unified file loading errors
Diffstat (limited to 'src/diag.rs')
| -rw-r--r-- | src/diag.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/diag.rs b/src/diag.rs index 76cad792..c4438307 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -1,6 +1,8 @@ //! Diagnostics. use std::fmt::{self, Display, Formatter}; +use std::io; +use std::path::Path; use crate::syntax::{Span, Spanned}; use crate::Context; @@ -134,3 +136,13 @@ pub fn with_alternative(msg: String, alt: &str) -> String { msg } } + +/// Format a file loading failure. +pub fn failed_to_load(target: &str, path: &Path, error: io::Error) -> String { + match error.kind() { + io::ErrorKind::NotFound => { + format!("file not found (searched at {})", path.display()) + } + _ => format!("failed to load {target} ({error})"), + } +} |
