Skip to main content

epochal_sandbox/
lib.rs

1#![doc = include_str!("../README.md")]
2
3mod exec;
4mod files;
5mod retry;
6mod sandbox;
7mod tunnel;
8
9use std::io;
10
11use epochal_api::Error as ApiError;
12
13pub use epochal_api::time_portal::sandbox::{
14    ExecExit, ExecFrame, FileStat, FileType, Network, Stream,
15};
16pub use epochal_api::{Client, chrono};
17pub use exec::{Command, Exec, Output};
18pub use files::Files;
19pub use sandbox::{Sandbox, SandboxBuilder};
20pub use tunnel::Tunnel;
21
22/// A failed call.
23#[derive(Debug, thiserror::Error)]
24#[non_exhaustive]
25pub enum Error {
26    /// An API call failed.
27    #[error(transparent)]
28    Api(#[from] ApiError),
29    /// The box ended or failed before it was live.
30    #[error("sandbox {id} did not come up: {}", reason.as_deref().unwrap_or("no reason given"))]
31    NotLive {
32        /// The box's id.
33        id: String,
34        /// Why, as the API put it.
35        reason: Option<String>,
36    },
37    /// A command this crate ran in the box, to move a directory, failed.
38    #[error("{step} failed: {stderr}")]
39    CommandFailed {
40        /// What the command was for.
41        step: String,
42        /// Its stderr.
43        stderr: String,
44    },
45    /// A local file could not be read or written.
46    #[error(transparent)]
47    Io(#[from] io::Error),
48    /// The box answered in a way this crate can't continue from.
49    #[error("unexpected: {0}")]
50    Unexpected(String),
51    /// The relay behind [`Sandbox::serve_http`] failed.
52    #[error("tunnel: {0}")]
53    Tunnel(String),
54}
55
56/// An argument this crate refuses before any call, as the API crate refuses its own.
57fn invalid(why: String) -> Error {
58    Error::Api(ApiError::InvalidArgument(why))
59}