Skip to main content

weirdnet_code_spaces/
error.rs

1//! The crate's error type.
2
3/// What can go wrong checking, building, loading or wiring code spaces. Messages are
4/// complete sentences an application can show as they are.
5#[derive(Debug, thiserror::Error)]
6pub enum SpacesError {
7    /// A source, plugin or line-up is wrong (`what` names the part: `math`, `plugin`, `space`, …).
8    #[error("invalid {what}: {msg}")]
9    Invalid { what: &'static str, msg: String },
10    /// Something needed is not there (`what`: "Rust toolchain", …), with what to do about it.
11    #[error("missing {what}: {hint}")]
12    Missing { what: &'static str, hint: String },
13    /// Cargo failed; the message has the end of its output.
14    #[error("{0}")]
15    Build(String),
16    #[error(transparent)]
17    Io(#[from] std::io::Error),
18}
19
20impl SpacesError {
21    pub fn invalid(what: &'static str, msg: impl Into<String>) -> Self {
22        SpacesError::Invalid { what, msg: msg.into() }
23    }
24    pub fn missing(what: &'static str, hint: impl Into<String>) -> Self {
25        SpacesError::Missing { what, hint: hint.into() }
26    }
27}
28
29pub(crate) type Error = SpacesError;
30pub type Result<T> = std::result::Result<T, SpacesError>;