统一错误处理
This commit is contained in:
@@ -20,6 +20,7 @@ pub enum AppErrorCode {
|
||||
IoError,
|
||||
ExternalCommandFailed,
|
||||
WindowOperationFailed,
|
||||
TaskExecutionFailed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, thiserror::Error)]
|
||||
@@ -50,6 +51,26 @@ impl AppCommandError {
|
||||
.with_detail(err.to_string())
|
||||
}
|
||||
|
||||
pub fn invalid_input(message: impl Into<String>) -> Self {
|
||||
Self::new(AppErrorCode::InvalidInput, message)
|
||||
}
|
||||
|
||||
pub fn configuration_invalid(message: impl Into<String>) -> Self {
|
||||
Self::new(AppErrorCode::ConfigurationInvalid, message)
|
||||
}
|
||||
|
||||
pub fn not_found(message: impl Into<String>) -> Self {
|
||||
Self::new(AppErrorCode::NotFound, message)
|
||||
}
|
||||
|
||||
pub fn network(message: impl Into<String>) -> Self {
|
||||
Self::new(AppErrorCode::NetworkError, message)
|
||||
}
|
||||
|
||||
pub fn task_execution_failed(message: impl Into<String>) -> Self {
|
||||
Self::new(AppErrorCode::TaskExecutionFailed, message)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn io(err: std::io::Error) -> Self {
|
||||
let code = match err.kind() {
|
||||
|
||||
Reference in New Issue
Block a user