voml_error/error/
mod.rs

1use std::{
2    convert::Infallible,
3    error::Error,
4    fmt::{Debug, Display, Formatter},
5};
6
7use diagnostic::{DiagnosticLevel, FileID, Span};
8
9mod for_std;
10
11/// All result about notedown
12pub type Result<T = ()> = std::result::Result<T, VomlError>;
13
14/// Many errors
15pub type Validation<T> = diagnostic::Validation<T, VomlError>;
16
17/// Error type for all Notedown operators
18#[derive(Debug)]
19pub struct VomlError {
20    /// Actual error kind
21    pub kind: Box<VomlErrorKind>,
22    /// Error level for report
23    pub level: DiagnosticLevel,
24    /// File name where error occurred
25    pub file: FileID,
26}
27
28/// Actual error data for the error
29#[derive(Debug)]
30pub enum VomlErrorKind {
31    /// The error type for I/O operations
32    IOError(std::io::Error),
33    /// The error type for I/O operations
34    ParseError(ParseFail),
35    /// Unknown error
36    UnknownError,
37}
38
39#[derive(Debug)]
40pub struct ParseFail {
41    pub message: String,
42    pub  span: Span,
43}
44
45impl Error for VomlError {}
46
47impl Display for VomlError {
48    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49        Debug::fmt(self, f)
50    }
51}
52
53impl Display for VomlErrorKind {
54    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
55        Debug::fmt(self, f)
56    }
57}