pub struct FrontError {
pub line: usize,
pub col: usize,
pub msg: String,
pub code: Box<Error>,
/* private fields */
}Expand description
Unified front-end error. line == 0 means “no position” (e.g. a purely semantic error).
The error is identified by a stable code (Error::code), not by a sentence: msg is the
rendering for the locale that was requested (English by default), and code is what tests
and callers match on. Messages that have not been catalogued yet carry
code == Error::Message(..) with their original text — an explicit staging marker, not a
silent fallback.
Fields§
§line: usize§col: usize§msg: StringRendering in i18n::Locale::En unless FrontError::in_locale produced a copy.
code: Box<Error>Implementations§
Source§impl FrontError
impl FrontError
pub fn new(line: usize, col: usize, msg: impl Into<Error>) -> Self
pub fn plain(msg: impl Into<Error>) -> Self
Sourcepub fn coded(code: Error, args: &[&str], line: usize, col: usize) -> Self
pub fn coded(code: Error, args: &[&str], line: usize, col: usize) -> Self
A catalogued error: the message is rendered from the code and its arguments.
The arguments are kept, so FrontError::in_locale can re-render the same error in
any of the nine languages without the caller having to hold them again.
Sourcepub fn render_in(&self, language: Locale) -> String
pub fn render_in(&self, language: Locale) -> String
Renders this error in language. Uncatalogued (Raw) errors keep their text.
Sourcepub fn in_locale(&self, language: Locale) -> Self
pub fn in_locale(&self, language: Locale) -> Self
Convenience: a copy whose msg is rendered in language.
Sourcepub fn localized(&self) -> Self
pub fn localized(&self) -> Self
Convenience: a copy rendered in HIMARI_LANG/LC_ALL/LANG, or English under no_std.
Sourcepub fn render_with_source(&self, origin: &str, src: &str) -> String
pub fn render_with_source(&self, origin: &str, src: &str) -> String
Contextual rendering: source line + caret.
Given only line:col, the user has to count by hand which character is in column 17;
quoting that line and drawing a ^ under the position is an editor-grade experience,
and it costs only a few lines of code.