Skip to main content

buntrail_core/contracts/
mod.rs

1pub mod async_types;
2pub mod document;
3pub mod file;
4pub mod git;
5pub mod language;
6pub mod operation;
7pub mod terminal;
8pub mod workspace;
9pub use document::*;
10pub use file::*;
11pub use git::*;
12pub use language::*;
13pub use operation::*;
14pub use terminal::*;
15pub use workspace::*;
16
17#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
18pub enum ErrorCode {
19    InvalidArgument,
20    StaleRevision,
21    Composition,
22    Unavailable,
23    WrongThread,
24    Closed,
25    Busy,
26    Cancelled,
27    Unknown,
28    TargetChanged,
29    InvalidTransition,
30    Io,
31    Poisoned,
32}
33#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
34pub enum ErrorContext {
35    None,
36    Document(DocumentID),
37    Target(Box<TargetIdentity>),
38    Operation(OperationID),
39    Request(RequestId),
40    Capability(Capability),
41}
42#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
43pub struct CoreError {
44    pub code: ErrorCode,
45    pub message: String,
46    pub context: ErrorContext,
47}
48impl CoreError {
49    pub fn new(code: ErrorCode, message: &str) -> Self {
50        Self {
51            code,
52            message: message.into(),
53            context: ErrorContext::None,
54        }
55    }
56}
57impl std::fmt::Display for CoreError {
58    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59        f.write_str(&self.message)
60    }
61}
62impl std::error::Error for CoreError {}