Skip to main content

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    /// A replication session failed.
68    #[error(transparent)]
69    Session(#[from] sapphire_framework_session::Error),
70
71    /// A configuration file that could not be read or written as expected.
72    #[error("{0}")]
73    Config(String),
74
75    /// Installing, removing or reporting this application's service failed.
76    ///
77    /// Carries the service crate's own message, which already says what to do about the
78    /// case at hand, or which platform offers what.
79    #[error(transparent)]
80    Service(#[from] sapphire_framework_service::Error),
81}
82
83/// Convenience alias for server results.
84pub type Result<T> = std::result::Result<T, Error>;