nibli_types/error.rs
1//! Structured error types shared across the pipeline.
2
3/// Detailed syntax error with source location.
4#[derive(Clone, Debug)]
5pub struct SyntaxDetail {
6 pub message: String,
7 pub line: u32,
8 pub column: u32,
9}
10
11/// Unified error type for the nibli-kr → nibli-semantics → nibli-reason pipeline.
12#[derive(Clone, Debug)]
13pub enum NibliError {
14 /// Syntax error from the parser (nibli-kr).
15 Syntax(SyntaxDetail),
16 /// Semantic error from the compiler (nibli-semantics).
17 Semantic(String),
18 /// Reasoning error from the inference engine (nibli-reason).
19 Reasoning(String),
20 /// Backend error from external compute dispatch. Fields: (predicate, message).
21 Backend((String, String)),
22}
23
24// FORMAL CONTRACT: the `[Syntax Error]` / `[Semantic Error]` / `[Reasoning Error]`
25// / `[Backend Error]` prefixes below are a stable cross-consumer interface — they
26// are the de-facto error CLASS encoding wherever the typed `NibliError` has been
27// flattened to a `String` (tavla's public API → nibli-server's `error_class`
28// classifier; nibli-host's `[Xxx Error]` REPL output; the nibli-ui `strip_prefix`
29// renderer). Do NOT change a prefix without updating those classifiers.
30impl std::fmt::Display for NibliError {
31 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 match self {
33 NibliError::Syntax(d) => {
34 write!(
35 f,
36 "[Syntax Error] line {}:{}: {}",
37 d.line, d.column, d.message
38 )
39 }
40 NibliError::Semantic(m) => write!(f, "[Semantic Error] {}", m),
41 NibliError::Reasoning(m) => write!(f, "[Reasoning Error] {}", m),
42 NibliError::Backend((k, m)) => write!(f, "[Backend Error] {} — {}", k, m),
43 }
44 }
45}