统一错误处理

This commit is contained in:
xintaofei
2026-03-07 16:40:59 +08:00
parent 100ce01fe1
commit dbcac80712
7 changed files with 243 additions and 187 deletions

View File

@@ -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() {