substrait_explain/parser/
errors.rs1use thiserror::Error;
2
3use super::MessageParseError;
4use super::extensions::ExtensionParseError;
5use crate::extensions::registry::ExtensionError;
6
7#[derive(Debug, Clone)]
9pub struct ParseContext {
10 pub line_no: i64,
11 pub line: String,
12}
13
14impl ParseContext {
15 pub fn new(line_no: i64, line: String) -> Self {
16 Self { line_no, line }
17 }
18}
19
20impl std::fmt::Display for ParseContext {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 write!(f, "line {}: '{}'", self.line_no, self.line)
23 }
24}
25
26#[derive(Debug, Clone, Error)]
28pub enum ParseError {
29 #[error("Error parsing extension on {0}: {1}")]
30 Extension(ParseContext, #[source] ExtensionParseError),
31
32 #[error("Error parsing extension detail on {0}: {1}")]
33 ExtensionDetail(ParseContext, #[source] ExtensionError),
34
35 #[error("Error parsing plan on {0}: {1}")]
36 Plan(ParseContext, #[source] MessageParseError),
37
38 #[error("Expected '{expected}' on {context}")]
39 Expected {
40 expected: &'static str,
41 context: ParseContext,
42 },
43
44 #[error("No relation found in plan")]
45 NoRelationFound,
46
47 #[error("Unregistered extension '{name}' on {context}")]
48 UnregisteredExtension { name: String, context: ParseContext },
49
50 #[error("Failed to parse relation on {0}: {1}")]
51 RelationParse(ParseContext, String),
52
53 #[error("Unknown extension relation type: {0}")]
54 UnknownExtensionRelationType(String),
55
56 #[error("Validation error: {0}")]
57 ValidationError(String),
58
59 #[error("Error parsing section header on line {0}: {1}")]
60 Initial(ParseContext, #[source] MessageParseError),
61
62 #[error("Error parsing relation: {0}")]
63 Relation(ParseContext, #[source] MessageParseError),
64}
65
66pub type ParseResult = Result<substrait::proto::Plan, ParseError>;