Skip to main content

cageforge_command/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Typed construction errors shared by [`crate::CommandSpec`],
4//! [`crate::EnvironmentSpec`], and [`crate::CommandRequest`].
5
6use std::path::PathBuf;
7
8use crate::EnvironmentBase;
9use thiserror::Error;
10
11/// Errors raised while constructing a portable command request.
12#[derive(Debug, Error, Clone, PartialEq, Eq)]
13pub enum CommandError {
14    /// The command program was empty.
15    #[error("command program must not be empty")]
16    EmptyProgram,
17    /// The command program contained a NUL character.
18    #[error("command program must not contain a NUL character")]
19    ProgramContainsNul,
20    /// A command argument contained a NUL character.
21    #[error("command argument must not contain a NUL character")]
22    ArgumentContainsNul,
23    /// The working-directory path was empty.
24    #[error("working directory must not be empty")]
25    EmptyWorkingDirectory,
26    /// The working-directory path contained a NUL character.
27    #[error("working directory must not contain a NUL character")]
28    WorkingDirectoryContainsNul,
29    /// The working-directory path contained a parent traversal component.
30    #[error(
31        "working directory must not contain parent traversal: {}",
32        path.display()
33    )]
34    WorkingDirectoryParentTraversal {
35        /// The working-directory path that attempted parent traversal.
36        path: PathBuf,
37    },
38    /// An environment variable name was empty.
39    #[error("environment variable name must not be empty")]
40    EmptyEnvironmentName,
41    /// An environment variable name contained `=`.
42    #[error("environment variable name must not contain '='")]
43    EnvironmentNameContainsEquals,
44    /// An environment variable name contained a NUL character.
45    #[error("environment variable name must not contain a NUL character")]
46    EnvironmentNameContainsNul,
47    /// An environment variable value contained a NUL character.
48    #[error("environment variable value must not contain a NUL character")]
49    EnvironmentValueContainsNul,
50    /// An environment-variable filter pattern was empty.
51    #[error("environment variable pattern must not be empty")]
52    EmptyEnvironmentPattern,
53    /// An environment-variable filter pattern contained a NUL character.
54    #[error("environment variable pattern must not contain a NUL character")]
55    EnvironmentPatternContainsNul,
56    /// An environment-variable filter pattern contained `=`.
57    #[error("environment variable pattern must not contain '='")]
58    EnvironmentPatternContainsEquals,
59    /// The supplied environment snapshot is broader than this specification's base.
60    #[error("environment input base {supplied:?} is broader than required base {required:?}")]
61    EnvironmentBaseTooPermissive {
62        /// The base requested by this specification.
63        required: EnvironmentBase,
64        /// The base represented by the supplied variables.
65        supplied: EnvironmentBase,
66    },
67}