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_agent::AgentError;
17use systemprompt_ai::error::RepositoryError as AiRepositoryError;
18use systemprompt_analytics::AnalyticsError;
19use systemprompt_config::paths::PathError;
20use systemprompt_config::{ConfigError as ProfileConfigError, ProfileBootstrapError};
21use systemprompt_content::ContentError;
22use systemprompt_database::RepositoryError;
23use systemprompt_extension::LoaderError;
24use systemprompt_files::FilesError;
25use systemprompt_marketplace::managed::ManagedError;
26use systemprompt_mcp::McpDomainError;
27use systemprompt_models::errors::ConfigError as ModelConfigError;
28use systemprompt_oauth::OauthError;
29use systemprompt_security::policy::GovernanceEngineError;
30use systemprompt_users::UserError;
31use thiserror::Error;
32
33pub type RuntimeResult<T> = Result<T, RuntimeError>;
34
35#[derive(Debug, Error)]
36pub enum RuntimeError {
37    #[error(transparent)]
38    Profile(#[from] ProfileConfigError),
39
40    #[error(transparent)]
41    ProfileBootstrap(#[from] ProfileBootstrapError),
42
43    #[error(transparent)]
44    Config(#[from] ModelConfigError),
45
46    #[error(transparent)]
47    Paths(#[from] PathError),
48
49    #[error(transparent)]
50    Files(#[from] FilesError),
51
52    #[error(transparent)]
53    Users(#[from] UserError),
54
55    #[error(transparent)]
56    Repository(#[from] RepositoryError),
57
58    #[error(transparent)]
59    Analytics(#[from] AnalyticsError),
60
61    #[error(transparent)]
62    AiRepository(#[from] AiRepositoryError),
63
64    #[error(transparent)]
65    Mcp(#[from] McpDomainError),
66
67    #[error(transparent)]
68    Agent(#[from] AgentError),
69
70    #[error(transparent)]
71    Content(#[from] ContentError),
72
73    #[error(transparent)]
74    Oauth(#[from] OauthError),
75
76    #[error(transparent)]
77    Loader(#[from] LoaderError),
78
79    #[error(transparent)]
80    Governance(#[from] GovernanceEngineError),
81
82    #[error(transparent)]
83    Managed(#[from] ManagedError),
84
85    #[error(
86        "Configured system admin '{username}' was not found in the users table. Run `systemprompt \
87         admin bootstrap` first."
88    )]
89    SystemAdminNotFound { username: String },
90
91    #[error(
92        "Configured system admin '{username}' exists but is not active. Re-activate the user \
93         before starting the platform."
94    )]
95    SystemAdminInactive { username: String },
96
97    #[error(
98        "Configured system admin '{username}' exists but does not carry the 'admin' role. Grant \
99         the role before starting the platform."
100    )]
101    SystemAdminMissingRole { username: String },
102
103    #[error(
104        "Configured GeoIP database at '{path}' could not be loaded: {message}. Fix or remove \
105         paths.geoip_database from the profile."
106    )]
107    GeoIpUnreadable { path: String, message: String },
108
109    #[error("DATABASE_URL is empty")]
110    EmptyDatabaseUrl,
111
112    #[error("Database not found at '{path}'. Run setup first")]
113    DatabaseNotFound { path: String },
114
115    #[error("Database path '{path}' exists but is not a file")]
116    DatabaseNotFile { path: String },
117
118    #[error("internal: {0}")]
119    Internal(String),
120}