Skip to main content

waratah_notebook/
error.rs

1//! Typed errors for the notebook sidecar service.
2
3use std::net::SocketAddr;
4use std::path::PathBuf;
5
6use thiserror::Error;
7
8/// Failure provisioning, starting, or supervising the notebook sidecar.
9#[derive(Debug, Error)]
10pub enum NotebookError {
11    /// The `notebooks.toml` config file could not be parsed.
12    #[error("invalid notebooks.toml: {source}")]
13    Config {
14        /// Underlying parse failure.
15        #[from]
16        source: toml::de::Error,
17    },
18
19    /// `notebooks.bind` could not be parsed as a socket address.
20    #[error("invalid notebooks bind address {addr}: {source}")]
21    InvalidBind {
22        /// The address string from the config file.
23        addr: String,
24        /// Parse failure.
25        source: std::net::AddrParseError,
26    },
27
28    /// Sidecar filesystem work (dirs, generated config) failed.
29    #[error(transparent)]
30    Io(#[from] std::io::Error),
31
32    /// The sidecar process could not be spawned.
33    #[error("could not spawn notebook sidecar {program}: {source}")]
34    Spawn {
35        /// Interpreter path that failed to start.
36        program: PathBuf,
37        /// Underlying spawn failure.
38        source: std::io::Error,
39    },
40
41    /// The sidecar never answered `GET /api` in time (fresh start).
42    #[error("notebook sidecar did not answer on {addr} in time")]
43    StartupTimeout {
44        /// Loopback address the sidecar was expected on.
45        addr: SocketAddr,
46    },
47
48    /// No free loopback port could be probed for the sidecar.
49    #[error("could not allocate a sidecar port on {bind}: {source}")]
50    PortProbe {
51        /// Bind address whose ephemeral pool was probed.
52        bind: SocketAddr,
53        /// Underlying bind failure.
54        source: std::io::Error,
55    },
56
57    /// No usable Python interpreter for the sidecar.
58    #[error("{0}")]
59    PythonUnavailable(String),
60
61    /// venv creation or `pip install` failed.
62    #[error("python environment provisioning failed: {0}")]
63    Provisioning(String),
64}