pub struct GraphQLParseError { /* private fields */ }Expand description
A parse error with location information and contextual notes.
This structure provides comprehensive error information for both human-readable CLI output and programmatic handling by tools.
Implementations§
Source§impl GraphQLParseError
impl GraphQLParseError
Sourcepub fn new(
message: impl Into<String>,
kind: GraphQLParseErrorKind,
source_span: SourceSpan,
) -> Self
pub fn new( message: impl Into<String>, kind: GraphQLParseErrorKind, source_span: SourceSpan, ) -> Self
Creates a new parse error with no notes.
Sourcepub fn with_notes(
message: impl Into<String>,
kind: GraphQLParseErrorKind,
notes: SmallVec<[GraphQLErrorNote; 2]>,
source_span: SourceSpan,
) -> Self
pub fn with_notes( message: impl Into<String>, kind: GraphQLParseErrorKind, notes: SmallVec<[GraphQLErrorNote; 2]>, source_span: SourceSpan, ) -> Self
Creates a new parse error with notes.
Sourcepub fn from_lexer_error(
message: impl Into<String>,
lexer_notes: SmallVec<[GraphQLErrorNote; 2]>,
source_span: SourceSpan,
) -> Self
pub fn from_lexer_error( message: impl Into<String>, lexer_notes: SmallVec<[GraphQLErrorNote; 2]>, source_span: SourceSpan, ) -> Self
Creates a parse error from a lexer error token.
When the parser encounters a GraphQLTokenKind::Error token,
this method converts it to a GraphQLParseError, preserving
the lexer’s message and notes.
Sourcepub fn source_span(&self) -> &SourceSpan
pub fn source_span(&self) -> &SourceSpan
Returns the pre-resolved source span for this error.
This span is resolved at construction time, so it is always
available without a SourceMap. When the error was
constructed without position info, this returns a
zero-position span.
The SourcePosition::byte_offset() values on
start_inclusive / end_exclusive carry the original byte
offsets that can be used for SpanMap lookup or
SourceMap::resolve_offset() calls.
Sourcepub fn kind(&self) -> &GraphQLParseErrorKind
pub fn kind(&self) -> &GraphQLParseErrorKind
Returns the categorized error kind.
Sourcepub fn notes(&self) -> &SmallVec<[GraphQLErrorNote; 2]>
pub fn notes(&self) -> &SmallVec<[GraphQLErrorNote; 2]>
Returns the additional notes for this error.
Sourcepub fn add_note_with_span(
&mut self,
message: impl Into<String>,
span: SourceSpan,
)
pub fn add_note_with_span( &mut self, message: impl Into<String>, span: SourceSpan, )
Adds a general note with a pre-resolved span (pointing to a related location).
Sourcepub fn add_help_with_span(
&mut self,
message: impl Into<String>,
span: SourceSpan,
)
pub fn add_help_with_span( &mut self, message: impl Into<String>, span: SourceSpan, )
Adds a help note with a pre-resolved span.
Sourcepub fn format_detailed(&self, source: Option<&str>) -> String
pub fn format_detailed(&self, source: Option<&str>) -> String
Formats this error as a diagnostic string for CLI output.
Produces output like:
error: Expected `:` after field name
--> schema.graphql:5:12
|
5 | userName String
| ^^^^^^
|
= note: Field definitions require `:` between name and type
= help: Did you mean: `userName: String`?All position information (file path, line, column) comes
from the pre-resolved source_span and note spans. The
optional source parameter provides the original source
text for snippet display — when None, the diagnostic
omits source snippets but still shows the error header,
location, and notes.
Sourcepub fn format_oneline(&self) -> String
pub fn format_oneline(&self) -> String
Formats this error as a single-line summary.
Produces output like:
schema.graphql:5:12: error: Expected `:` after field nameThis is equivalent to the Display impl. Prefer using
format!("{error}") or error.to_string() directly.
Trait Implementations§
Source§impl Clone for GraphQLParseError
impl Clone for GraphQLParseError
Source§fn clone(&self) -> GraphQLParseError
fn clone(&self) -> GraphQLParseError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GraphQLParseError
impl Debug for GraphQLParseError
Source§impl Display for GraphQLParseError
impl Display for GraphQLParseError
Source§impl Error for GraphQLParseError
impl Error for GraphQLParseError
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()