pub struct Diagnostic { /* private fields */ }Expand description
A build-time template-authoring diagnostic.
Construct with Diagnostic::error / Diagnostic::warning, attach
context with the builder methods, then return it inside
crate::ParserError::Template. The library never colors or prints it; the
CLI reads the fields via the getters and renders them, while other hosts use
the plain fmt::Display text.
Implementations§
Source§impl Diagnostic
impl Diagnostic
Sourcepub fn error(title: impl Into<String>) -> Self
pub fn error(title: impl Into<String>) -> Self
Start a fatal error diagnostic. Titles are short and lowercase by
convention (e.g. invalid @click handler).
Sourcepub fn warning(title: impl Into<String>) -> Self
pub fn warning(title: impl Into<String>) -> Self
Start a non-fatal warning diagnostic.
Rendered with the same location/snippet/help: layout as an error, but
the build continues (e.g. an unthemed literal-fallback CSS token).
Sourcepub fn component(self, component: impl Into<String>) -> Self
pub fn component(self, component: impl Into<String>) -> Self
Name the owning component template (e.g. mail-inbox-page).
Sourcepub fn element(self, element: impl Into<String>) -> Self
pub fn element(self, element: impl Into<String>) -> Self
Name the offending element tag (e.g. button), when known.
Sourcepub fn snippet(self, snippet: impl Into<String>) -> Self
pub fn snippet(self, snippet: impl Into<String>) -> Self
Attach the offending source snippet (e.g. @click="bad()").
Sourcepub fn position(self, line: usize, column: usize) -> Self
pub fn position(self, line: usize, column: usize) -> Self
Attach the 1-based (line, column) of the offending source location.
Sourcepub fn at_offset(self, source: &str, offset: usize) -> Self
pub fn at_offset(self, source: &str, offset: usize) -> Self
Attach the source location computed from a byte offset into source.
Convenience over Diagnostic::position for callers that hold the
source text and a byte offset (e.g. an element’s start). Computes the
1-based line and column in a single forward scan.
Sourcepub fn error_code(&self) -> Option<&'static str>
pub fn error_code(&self) -> Option<&'static str>
The stable, machine-readable error code, if set.
Sourcepub fn component_name(&self) -> Option<&str>
pub fn component_name(&self) -> Option<&str>
The owning component tag, if set.
Sourcepub fn element_name(&self) -> Option<&str>
pub fn element_name(&self) -> Option<&str>
The offending element tag, if set.
Sourcepub fn snippet_text(&self) -> Option<&str>
pub fn snippet_text(&self) -> Option<&str>
The offending source snippet, if set.
Sourcepub fn position_line_column(&self) -> Option<(usize, usize)>
pub fn position_line_column(&self) -> Option<(usize, usize)>
The 1-based (line, column) of the offending source location, if known.
Sourcepub fn location(&self) -> Option<String>
pub fn location(&self) -> Option<String>
Render the location line content (already including its leading marker), if any.
When a source position is known it is reported rustc-style as
--> owner:line:column (the owner is the entry file or component
tag), which is compact and recognizable. Without a position it falls
back to a descriptive in component <c> · element <e> form. Returned so
callers (e.g. the CLI) can render the location on its own styled line.
Sourcepub fn body(&self) -> String
pub fn body(&self) -> String
Render the message body — everything after the severity label: title,
location, offending snippet, and help: hint, each on its own line.
Used by callers that supply their own leading label (e.g. the dev
server prints build error: {body}) so the severity word isn’t
duplicated. fmt::Display prepends the severity to this body.