Skip to main content

ferrin_policy/
error.rs

1//! Errors of policy evaluation.
2
3use http::StatusCode;
4
5/// Why a policy could not be evaluated.
6///
7/// Approval policies built with [`policy_approval`](crate::policy_approval)
8/// turn these into a denial (or fall through, see
9/// [`FailureMode`](crate::FailureMode)); the error is exposed for callers
10/// that evaluate a [`PolicyClient`](crate::PolicyClient) directly.
11#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
12#[non_exhaustive]
13pub enum PolicyError {
14    /// The policy path is empty or contains an empty or blank segment.
15    #[error("invalid policy path `{path}`: {message}")]
16    InvalidPath {
17        /// The rejected path.
18        path: String,
19        /// Explanation.
20        message: String,
21    },
22    /// The policy server URL was rejected by the URL policy or cannot carry
23    /// the data path.
24    #[error("invalid policy url: {message}")]
25    InvalidUrl {
26        /// Explanation.
27        message: String,
28    },
29    /// The policy input could not be encoded.
30    #[error("invalid policy input: {message}")]
31    InvalidInput {
32        /// Explanation.
33        message: String,
34    },
35    /// The request to the policy server failed below the HTTP status layer
36    /// (connection, TLS, timeout, body limits).
37    #[error("policy request to {host} failed: {message}")]
38    Transport {
39        /// Host of the policy server.
40        host: String,
41        /// Explanation.
42        message: String,
43    },
44    /// The policy server answered with a non-success status.
45    #[error("policy server returned HTTP {status}")]
46    Status {
47        /// The status code.
48        status: StatusCode,
49        /// The start of the response body (at most 1 KiB).
50        body: String,
51    },
52    /// The response body is not the expected JSON document.
53    #[error("policy response is not valid: {message}")]
54    InvalidResponse {
55        /// Explanation.
56        message: String,
57    },
58    /// The embedded policy engine rejected the policy, the data document or
59    /// the rule path, or failed during evaluation.
60    #[error("policy engine error: {message}")]
61    Engine {
62        /// Engine message.
63        message: String,
64    },
65}