shell_candy/
error.rs

1#[cfg(doc)]
2use crate::ShellTask;
3
4use thiserror::Error as ThisError;
5
6use std::{io, process::ExitStatus};
7
8/// The result type used by a [`ShellTask`].
9pub type Result<T> = std::result::Result<T, Error>;
10
11/// The possible errors reported by a [`ShellTask`].
12#[derive(ThisError, Debug)]
13pub enum Error {
14    /// This error occurs when a command exits with a status other than 0.
15    #[error("'{task}' failed with {exit_status}.")]
16    TaskFailure {
17        /// The task that failed.
18        task: String,
19
20        /// The exit status that was returned.
21        exit_status: ExitStatus,
22    },
23
24    /// This error occurs when a task could not be instantiated because it was malformed.
25    /// This is a usage error, make sure you've typed the command correctly.
26    #[error("'{task}' is not a valid command because {reason}.")]
27    InvalidTask {
28        /// The malformed task.
29        task: String,
30
31        /// The reason the task was malformed.
32        reason: String,
33    },
34
35    /// This error occurs when a task could not spawn. Originates from [`std::process::Command::spawn`].
36    #[error("could not spawn '{task}': {source}.")]
37    CouldNotSpawn {
38        /// The task that could not spawn.
39        task: String,
40
41        /// The [`io::Error`] that was reported by [`std::process::Command::spawn`].
42        source: io::Error,
43    },
44
45    /// There was an error waiting for the task status. Originates from [`std::process::Child::wait`].
46    #[error("could not wait for '{task}' to complete: {source}.")]
47    CouldNotWait {
48        /// The task that could not be waited for.
49        task: String,
50
51        /// The [`io::Error`] that was reported by [`std::process::Child::wait`].
52        source: io::Error,
53    },
54
55    /// This error is returned when the current directory cannot be found. Originates from [`std::env::current_dir`].
56    #[error("could not find current directory when initializing task: {source}.")]
57    CouldNotFindCurrentDirectory {
58        /// The [`io::Error`] that was reported by [`std::env::current_dir`].
59        source: io::Error,
60    },
61
62    /// This error can be returned from log handlers to terminate early.
63    #[error(transparent)]
64    EarlyReturn(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
65
66    /// This error is returned when the log lock is poisoned.
67    #[error("encountered an unrecoverable error while processing logs for '{task}'.")]
68    PoisonedLog {
69        /// The task that encountered an unrecoverable error
70        task: String,
71    },
72}