Files
marqdo-lint/src/error.rs
T

41 lines
901 B
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum LintError {
#[error("无法读取 {path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("{path} 不是有效 UTF-8:{source}")]
Utf8 {
path: PathBuf,
#[source]
source: std::str::Utf8Error,
},
#[error("协议错误:{0}")]
Protocol(String),
#[error("Marqdo 核心调用失败:{0}")]
Core(String),
#[error("{0}")]
UnsafeFix(String),
#[error("配置错误:{0}")]
Config(String),
}
pub type Result<T> = std::result::Result<T, LintError>;
impl From<LintError> for String {
fn from(error: LintError) -> Self {
error.to_string()
}
}
pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> LintError {
LintError::Io {
path: path.into(),
source,
}
}