rootless_run/
error.rs

1//! Error handling for rootless backends.
2
3use std::process::ExitStatus;
4
5#[cfg(doc)]
6use crate::RootlessBackend;
7use crate::utils::SystemdDetectVirtOutput;
8
9/// An error that can occur when using a rootless backend.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    /// An executable that is supposed to be called, is not found.
13    #[error("Unable to to find executable: \"{executable}\"")]
14    ExecutableNotFound {
15        /// The executable that could not be found.
16        executable: String,
17        /// The source error.
18        source: which::Error,
19    },
20
21    /// A command could not be executed.
22    #[error("The command \"{command}\" could not be executed:\n{source}")]
23    CommandExec {
24        /// The command that could not be executed.
25        command: String,
26        /// The source error.
27        source: std::io::Error,
28    },
29
30    /// A command exited unsuccessfully.
31    #[error(
32        "The command \"{command}\" exited with non-zero status code \"{exit_status}\":\nstderr:\n{stderr}"
33    )]
34    CommandNonZero {
35        /// The command that exited with a non-zero exit code.
36        command: String,
37        /// The exit status of `command`.
38        exit_status: ExitStatus,
39        /// The stderr of `command`.
40        stderr: String,
41    },
42
43    /// Unknown output of [systemd-detect-virt] detected.
44    ///
45    /// [systemd-detect-virt]: https://man.archlinux.org/man/systemd-detect-virt.1
46    #[error("Unknown output of \"systemd-detect-virt\": \"{output}\"")]
47    UnknownSystemdDetectVirtOutput {
48        /// The unknown output for [systemd-detect-virt].
49        output: String,
50    },
51
52    /// A [`RootlessBackend`] based on kernel namespaces is used in a container runtime.
53    #[error(
54        "Rootless backends based on kernel namespaces are not supported in the \"{runtime}\" containerization runtime."
55    )]
56    NamespacesInContainer {
57        /// The container runtime in which the [`RootlessBackend`] based on kernel namespaces is
58        /// used.
59        runtime: SystemdDetectVirtOutput,
60    },
61}