sapphire_framework_server/error.rs
1use thiserror::Error;
2
3/// Errors raised while serving an application's workspaces.
4#[derive(Debug, Error)]
5pub enum Error {
6 /// Opening or using a workspace failed.
7 #[error(transparent)]
8 Workspace(#[from] sapphire_workspace::Error),
9
10 /// A backend operation failed.
11 #[error(transparent)]
12 Backend(#[from] sapphire_backend::Error),
13
14 /// The IPC layer failed.
15 #[error(transparent)]
16 Ipc(#[from] sapphire_ipc::Error),
17
18 /// Finding, verifying or installing a release failed.
19 #[error(transparent)]
20 Update(#[from] sapphire_framework_update::Error),
21
22 /// Listening, or preparing the runtime directory, failed.
23 #[error(transparent)]
24 Io(#[from] std::io::Error),
25
26 /// The request named a directory that is not a workspace of this application.
27 #[error("{0} is not a {1} workspace")]
28 UnknownWorkspace(std::path::PathBuf, &'static str),
29
30 /// The server has no workspace yet, or the one asked for is no longer current (#215).
31 #[error(
32 "this server has no workspace yet; run `workspace init <dir>` or `workspace select <dir>`"
33 )]
34 NoWorkspace,
35
36 /// The workgroup has no workspace with this name or id.
37 #[error("the workgroup has no workspace {0}")]
38 UnknownWorkspaceName(String),
39
40 /// The workgroup workspace belongs to another application.
41 #[error("workspace {name} belongs to {app_name}, not this application")]
42 WrongApp {
43 /// The workspace's name.
44 name: String,
45 /// The application that owns it.
46 app_name: String,
47 },
48
49 /// A workspace's sync identity could not be read or written.
50 ///
51 /// Never repaired by minting a new identity: the workspace may already exist on
52 /// another device, and a second identity would make the two sync as unrelated
53 /// workspaces for ever.
54 #[error("{0}")]
55 SyncId(String),
56
57 /// The replication core failed.
58 ///
59 /// Carries its error's `Display`, not the error: the core's own type is an internal
60 /// detail, while the message is what status and the logs need.
61 #[error("replication failed: {0}")]
62 Sync(String),
63
64 /// The bridge refused a request, or could not be reached.
65 ///
66 /// Not fatal to the app server: the bridge carries replication, and everything the
67 /// application itself does works without it (spec ยง10).
68 #[error("the bridge could not be reached: {0}")]
69 Bridge(String),
70
71 /// The server has no connection to the bridge right now: it was not running when the
72 /// server started, or it stopped since. The server reconnects on its own (#244).
73 #[error(
74 "not connected to sapphire-bridge; this server reconnects on its own once the bridge is running"
75 )]
76 BridgeDisconnected,
77
78 /// A replication session failed.
79 #[error(transparent)]
80 Session(#[from] sapphire_framework_session::Error),
81
82 /// A configuration file that could not be read or written as expected.
83 #[error("{0}")]
84 Config(String),
85
86 /// Reading or writing the settings failed, or they were refused.
87 #[error(transparent)]
88 Settings(#[from] sapphire_framework_settings::Error),
89
90 /// The MCP session on stdio could not start or ended abnormally.
91 #[error("{0}")]
92 Mcp(String),
93
94 /// Installing, removing or reporting this application's service failed.
95 ///
96 /// Carries the service crate's own message, which already says what to do about the
97 /// case at hand, or which platform offers what.
98 #[error(transparent)]
99 Service(#[from] sapphire_framework_service::Error),
100}
101
102/// Convenience alias for server results.
103pub type Result<T> = std::result::Result<T, Error>;