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//! Third-party errors without a `#[from]` adapter are stringified into
10//! the [`RuntimeError::Internal`] variant at the call site so the lossy
11//! conversion is visible.
12//!
13//! Copyright (c) systemprompt.io — Business Source License 1.1.
14//! See <https://systemprompt.io> for licensing details.
15
16use systemprompt_analytics::AnalyticsError;
17use systemprompt_config::{ConfigError as ProfileConfigError, ProfileBootstrapError};
18use systemprompt_database::RepositoryError;
19use systemprompt_extension::LoaderError;
20use systemprompt_files::FilesError;
21use systemprompt_models::errors::ConfigError as ModelConfigError;
22use systemprompt_models::paths::PathError;
23use systemprompt_users::UserError;
24use thiserror::Error;
25
26pub type RuntimeResult<T> = Result<T, RuntimeError>;
27
28#[derive(Debug, Error)]
29pub enum RuntimeError {
30    #[error(transparent)]
31    Profile(#[from] ProfileConfigError),
32
33    #[error(transparent)]
34    ProfileBootstrap(#[from] ProfileBootstrapError),
35
36    #[error(transparent)]
37    Config(#[from] ModelConfigError),
38
39    #[error(transparent)]
40    Paths(#[from] PathError),
41
42    #[error(transparent)]
43    Files(#[from] FilesError),
44
45    #[error(transparent)]
46    Users(#[from] UserError),
47
48    #[error(transparent)]
49    Repository(#[from] RepositoryError),
50
51    #[error(transparent)]
52    Analytics(#[from] AnalyticsError),
53
54    #[error(transparent)]
55    Loader(#[from] LoaderError),
56
57    #[error(
58        "Configured system admin '{username}' was not found in the users table. Run `systemprompt \
59         admin bootstrap` first."
60    )]
61    SystemAdminNotFound { username: String },
62
63    #[error(
64        "Configured system admin '{username}' exists but is not active. Re-activate the user \
65         before starting the platform."
66    )]
67    SystemAdminInactive { username: String },
68
69    #[error(
70        "Configured system admin '{username}' exists but does not carry the 'admin' role. Grant \
71         the role before starting the platform."
72    )]
73    SystemAdminMissingRole { username: String },
74
75    #[error("DATABASE_URL is empty")]
76    EmptyDatabaseUrl,
77
78    #[error("Database not found at '{path}'. Run setup first")]
79    DatabaseNotFound { path: String },
80
81    #[error("Database path '{path}' exists but is not a file")]
82    DatabaseNotFile { path: String },
83
84    #[error("internal: {0}")]
85    Internal(String),
86}