Skip to main content

systemprompt_runtime/
error.rs

1//! Typed error boundary for the runtime crate.
2//!
3//! All public APIs of `systemprompt-runtime` return [`RuntimeResult<T>`]
4//! (i.e. `Result<T, RuntimeError>`). [`RuntimeError`] composes the typed
5//! errors of upstream layers (config, database, events, files, users,
6//! extensions) via `#[from]` so callers can pattern-match on the original
7//! cause without losing fidelity.
8//!
9//! Calls into upstream crates that still return `anyhow::Result` (for
10//! example schema/seed installation and database connectivity probes)
11//! are stringified into the [`RuntimeError::Internal`] variant at the
12//! call site so the lossy conversion is visible.
13
14use systemprompt_analytics::AnalyticsError;
15use systemprompt_config::{ConfigError as ProfileConfigError, ProfileBootstrapError};
16use systemprompt_database::RepositoryError;
17use systemprompt_extension::LoaderError;
18use systemprompt_files::FilesError;
19use systemprompt_models::errors::ConfigError as ModelConfigError;
20use systemprompt_models::paths::PathError;
21use systemprompt_users::UserError;
22use thiserror::Error;
23
24pub type RuntimeResult<T> = Result<T, RuntimeError>;
25
26#[derive(Debug, Error)]
27pub enum RuntimeError {
28    #[error(transparent)]
29    Profile(#[from] ProfileConfigError),
30
31    #[error(transparent)]
32    ProfileBootstrap(#[from] ProfileBootstrapError),
33
34    #[error(transparent)]
35    Config(#[from] ModelConfigError),
36
37    #[error(transparent)]
38    Paths(#[from] PathError),
39
40    #[error(transparent)]
41    Files(#[from] FilesError),
42
43    #[error(transparent)]
44    Users(#[from] UserError),
45
46    #[error(transparent)]
47    Repository(#[from] RepositoryError),
48
49    #[error(transparent)]
50    Analytics(#[from] AnalyticsError),
51
52    #[error(transparent)]
53    Loader(#[from] LoaderError),
54
55    #[error("DATABASE_URL is empty")]
56    EmptyDatabaseUrl,
57
58    #[error("Database not found at '{path}'. Run setup first")]
59    DatabaseNotFound { path: String },
60
61    #[error("Database path '{path}' exists but is not a file")]
62    DatabaseNotFile { path: String },
63
64    #[error("internal: {0}")]
65    Internal(String),
66}