cageforge_policy_compose/
error.rs1use std::path::PathBuf;
6
7use cageforge_command::{CommandError, EnvironmentBase};
8use cageforge_policy::PolicyError;
9use thiserror::Error;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum CompositionBoundary {
14 Filesystem,
16 Network,
18}
19
20#[derive(Debug, Error, Clone, PartialEq, Eq)]
22pub enum CompositionError {
23 #[error("requested sandbox policy is invalid: {source}")]
25 InvalidRequestedPolicy {
26 #[source]
28 source: PolicyError,
29 },
30 #[error("policy ceiling is invalid: {source}")]
32 InvalidCeiling {
33 #[source]
35 source: PolicyError,
36 },
37 #[error("invalid workspace root {path:?}: {reason}")]
39 InvalidWorkspaceRoot {
40 path: PathBuf,
42 reason: &'static str,
44 },
45 #[error("requested workspace root {path:?} is outside the policy ceiling")]
47 WorkspaceRootNotGranted {
48 path: PathBuf,
50 },
51 #[error("effective path context is invalid: {source}")]
53 InvalidPathContext {
54 #[source]
56 source: PolicyError,
57 },
58 #[error("effective path context belongs to a different composed sandbox")]
60 PathContextMismatch,
61 #[error("environment input base {supplied:?} is broader than effective base {required:?}")]
64 EnvironmentBaseTooPermissive {
65 required: EnvironmentBase,
67 supplied: EnvironmentBase,
69 },
70 #[error("environment transformation failed: {source}")]
72 EnvironmentApplication {
73 #[source]
75 source: CommandError,
76 },
77 #[error("{boundary} enforcement ownership cannot be composed safely")]
79 EnforcementOwnershipConflict {
80 boundary: CompositionBoundary,
82 },
83 #[error("{boundary} external enforcement requires one shared owner proof")]
85 ExternalOwnerMismatch {
86 boundary: CompositionBoundary,
88 },
89 #[error("{boundary} external owner proof is only valid for external enforcement")]
91 UnexpectedExternalOwner {
92 boundary: CompositionBoundary,
94 },
95 #[error("{boundary} policy evaluation failed: {source}")]
97 PolicyEvaluation {
98 boundary: CompositionBoundary,
100 #[source]
102 source: PolicyError,
103 },
104}
105
106impl std::fmt::Display for CompositionBoundary {
107 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108 match self {
109 Self::Filesystem => formatter.write_str("filesystem"),
110 Self::Network => formatter.write_str("network"),
111 }
112 }
113}