pub struct CELError { /* private fields */ }Expand description
A CEL parse error with a message and source location.
Uses a SourceSpan (line/column only) so the error is Send + Sync and
can be used from async execution or reported across thread boundaries.
Implementations§
Source§impl CELError
impl CELError
Sourcepub fn new(message: impl Into<String>, span: SourceSpan) -> Self
pub fn new(message: impl Into<String>, span: SourceSpan) -> Self
Creates a new error with the given message and source span.
§Examples
use cel_parser::CELError;
use cel_parser::SourceSpan;
let span = SourceSpan::default();
let e = CELError::new("unexpected token", span);
assert_eq!(e.message(), "unexpected token");Sourcepub fn message(&self) -> &str
pub fn message(&self) -> &str
Returns the error message.
§Examples
use cel_parser::CELError;
use cel_parser::SourceSpan;
let e = CELError::new("bad input", SourceSpan::default());
assert_eq!(e.message(), "bad input");Sourcepub fn span(&self) -> SourceSpan
pub fn span(&self) -> SourceSpan
Returns the source span for this error.
§Examples
use cel_parser::CELError;
use cel_parser::SourceSpan;
let span = SourceSpan::default();
let e = CELError::new("bad input", span);
assert_eq!(e.span(), span);Sourcepub fn format_rustc_style(
&self,
source_code: &str,
filename: &str,
start_line: u32,
renderer: &Renderer,
) -> String
pub fn format_rustc_style( &self, source_code: &str, filename: &str, start_line: u32, renderer: &Renderer, ) -> String
Formats this error in rustc diagnostic style with source context.
Produces a multi-line string matching Rust compiler diagnostic output, including the source file location, error message, and a caret indicating the error position. Uses annotate-snippets for rendering.
Pass [Renderer::plain] for tests and non-ANSI contexts; pass
[Renderer::styled] for terminal output.
§Examples
use annotate_snippets::Renderer;
use cel_parser::CELParser;
use cel_parser::op_table::OpLookup;
use cel_parser::CELError;
let line = line!() + 1;
let source = r#"
10 + 20 30
"#;
let mut parser = CELParser::new(OpLookup::new());
if let Err(e) = parser.parse_str(source) {
let e: CELError = e.into();
println!("{}", e.format_rustc_style(source, file!(), line, &Renderer::styled()));
}Trait Implementations§
Source§impl Error for CELError
impl Error for CELError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<ParseError> for CELError
Converts a ParseError to a CELError by extracting the
SourceSpan from the token span.
impl From<ParseError> for CELError
Converts a ParseError to a CELError by extracting the
SourceSpan from the token span.
Use this at async/runtime boundaries where Send + Sync is required.