You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use miette to have nice error messages in a compiler I made, but I can't figure out how to properly do it. I've reproduced a minimal example:
use miette::{NamedSource,SourceSpan};#[derive(Debug, miette::Diagnostic, thiserror::Error)]enumAppError{#[error("analyze error")]AnalyzerError(#[diagnostic_source]#[source]AnalyzerError,),}#[derive(Debug, miette::Diagnostic, thiserror::Error)]enumAnalyzerError{#[error("variable '{varname}' already defined")]#[diagnostic(code(variable_already_defined))]VariableAlreadyDefined{varname:String,#[source_code]src:NamedSource<String>,#[label("here")]definition:SourceSpan,#[label("first defined here")]first_definition:SourceSpan,},#[error("variable '{varname}' not found")]#[diagnostic(code(variable_not_found))]VariableNotFound{varname:String,#[source_code]src:NamedSource<String>,#[label("used here")]used:SourceSpan,},}fnmain() -> miette::Result<(),AppError>{let src = "entier a = 5;\necrire(a);\nentier a = 7;".to_string();Err(AppError::AnalyzerError(AnalyzerError::VariableAlreadyDefined{varname:"a".to_string(),src:NamedSource::new("testing.flo", src),first_definition:(0,12).into(),definition:(25,12).into(),},))?;Ok(())}
But this just prints Error: AnalyzerError(VariableAlreadyDefined { ... }) in terminal, not the fancy diagnostic message (I've enabled the fancy feature). Any help would be much appreciated!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to use miette to have nice error messages in a compiler I made, but I can't figure out how to properly do it. I've reproduced a minimal example:
But this just prints
Error: AnalyzerError(VariableAlreadyDefined { ... })
in terminal, not the fancy diagnostic message (I've enabled thefancy
feature). Any help would be much appreciated!Beta Was this translation helpful? Give feedback.
All reactions