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