1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum ParseError {
6 #[error("YAML parse error at line {line}, column {column}: {message}")]
8 Syntax {
9 line: usize,
11 column: usize,
13 message: String,
15 },
16
17 #[error("invalid float value '{value}': {source}")]
19 InvalidFloat {
20 value: String,
22 #[source]
24 source: std::num::ParseFloatError,
25 },
26
27 #[error("YAML scanner error: {0}")]
29 Scanner(#[from] saphyr::ScanError),
30}
31
32#[derive(Error, Debug)]
34pub enum EmitError {
35 #[error("failed to emit YAML: {0}")]
37 Emit(String),
38
39 #[error("unsupported type for serialization: {0}")]
41 UnsupportedType(String),
42}
43
44pub type ParseResult<T> = std::result::Result<T, ParseError>;
46
47pub type EmitResult<T> = std::result::Result<T, EmitError>;
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_parse_error_display() {
56 let err = ParseError::Syntax {
57 line: 10,
58 column: 5,
59 message: "unexpected token".to_string(),
60 };
61 assert!(err.to_string().contains("line 10"));
62 assert!(err.to_string().contains("column 5"));
63 }
64
65 #[test]
66 fn test_emit_error_display() {
67 let err = EmitError::UnsupportedType("CustomType".to_string());
68 assert!(err.to_string().contains("CustomType"));
69 }
70}