feat: add main features
Agents for developpement added + frontend add + backend added. Git viewer created + agent and template creator + layout and project creator
This commit is contained in:
115
crates/application/src/error.rs
Normal file
115
crates/application/src/error.rs
Normal file
@ -0,0 +1,115 @@
|
||||
//! [`AppError`] — the single error type returned by every use case.
|
||||
//!
|
||||
//! Per-port errors from the domain ([`domain::ports::FsError`],
|
||||
//! [`domain::ports::StoreError`], …) are mapped into this application-level
|
||||
//! error so that the presentation layer (Tauri commands) only ever has to deal
|
||||
//! with one error shape when building its `ErrorDTO`.
|
||||
|
||||
use domain::ports::{
|
||||
FsError, GitError, ProcessError, PtyError, RemoteError, RuntimeError, StoreError,
|
||||
};
|
||||
|
||||
/// Errors surfaced by application use cases.
|
||||
///
|
||||
/// Each variant carries a stable, machine-readable `code` (see [`AppError::code`])
|
||||
/// so the presentation layer can map it to an `ErrorDTO` without string matching.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
/// A requested resource was not found.
|
||||
#[error("not found: {0}")]
|
||||
NotFound(String),
|
||||
|
||||
/// The input failed a domain/application invariant.
|
||||
#[error("invalid input: {0}")]
|
||||
Invalid(String),
|
||||
|
||||
/// A filesystem operation failed.
|
||||
#[error("filesystem error: {0}")]
|
||||
FileSystem(String),
|
||||
|
||||
/// A persistence (store) operation failed.
|
||||
#[error("store error: {0}")]
|
||||
Store(String),
|
||||
|
||||
/// A process/PTY/runtime operation failed.
|
||||
#[error("process error: {0}")]
|
||||
Process(String),
|
||||
|
||||
/// A git operation failed.
|
||||
#[error("git error: {0}")]
|
||||
Git(String),
|
||||
|
||||
/// A remote (SSH/WSL) operation failed.
|
||||
#[error("remote error: {0}")]
|
||||
Remote(String),
|
||||
|
||||
/// An unexpected internal error.
|
||||
#[error("internal error: {0}")]
|
||||
Internal(String),
|
||||
}
|
||||
|
||||
impl AppError {
|
||||
/// A stable, machine-readable code for this error, intended for the
|
||||
/// `ErrorDTO` so the frontend can branch without parsing messages.
|
||||
#[must_use]
|
||||
pub fn code(&self) -> &'static str {
|
||||
match self {
|
||||
Self::NotFound(_) => "NOT_FOUND",
|
||||
Self::Invalid(_) => "INVALID",
|
||||
Self::FileSystem(_) => "FILESYSTEM",
|
||||
Self::Store(_) => "STORE",
|
||||
Self::Process(_) => "PROCESS",
|
||||
Self::Git(_) => "GIT",
|
||||
Self::Remote(_) => "REMOTE",
|
||||
Self::Internal(_) => "INTERNAL",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FsError> for AppError {
|
||||
fn from(e: FsError) -> Self {
|
||||
match e {
|
||||
FsError::NotFound(p) => Self::NotFound(p),
|
||||
other => Self::FileSystem(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StoreError> for AppError {
|
||||
fn from(e: StoreError) -> Self {
|
||||
match e {
|
||||
StoreError::NotFound => Self::NotFound("store item".to_owned()),
|
||||
other => Self::Store(other.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PtyError> for AppError {
|
||||
fn from(e: PtyError) -> Self {
|
||||
Self::Process(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProcessError> for AppError {
|
||||
fn from(e: ProcessError) -> Self {
|
||||
Self::Process(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RuntimeError> for AppError {
|
||||
fn from(e: RuntimeError) -> Self {
|
||||
Self::Process(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<GitError> for AppError {
|
||||
fn from(e: GitError) -> Self {
|
||||
Self::Git(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RemoteError> for AppError {
|
||||
fn from(e: RemoteError) -> Self {
|
||||
Self::Remote(e.to_string())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user