cedar_policy_core/authorizer/err.rs
1/*
2 * Copyright Cedar Contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::ast::*;
18use crate::evaluator::EvaluationError;
19use miette::Diagnostic;
20use smol_str::SmolStr;
21use thiserror::Error;
22
23/// Errors that can occur during authorization
24#[derive(Debug, PartialEq, Eq, Clone, Diagnostic, Error)]
25pub enum AuthorizationError {
26 /// An error occurred when evaluating a policy.
27 #[error("while evaluating policy `{id}`: {error}")]
28 PolicyEvaluationError {
29 /// Id of the policy with an error
30 id: PolicyID,
31 /// Underlying evaluation error
32 #[diagnostic(transparent)]
33 error: EvaluationError,
34 },
35}
36
37/// Errors that occur during concretizing a partial request
38#[derive(Debug, Error, Diagnostic)]
39pub enum ConcretizationError {
40 /// Errors that occur when binding unknowns with values of unexpected types
41 #[error("invalid value {given_value} of {id}: expected type {expected_type}")]
42 ValueError {
43 /// String representation of PARC
44 id: SmolStr,
45 /// Expected type of the provided value
46 expected_type: &'static str,
47 /// The provided value
48 given_value: Value,
49 },
50 /// Errors that occur when binding variables with known values
51 #[error("concretizing existing value {existing_value} of {id} with value {given_value}")]
52 VarConfictError {
53 /// String representation of PARC
54 id: SmolStr,
55 /// Existing value of PARC
56 existing_value: PartialValue,
57 /// The provided value
58 given_value: Value,
59 },
60 /// Errors that occur when binding variables with known values
61 #[error("concretizing existing but unknown entity value of type {existing_value} of {id} with value {given_value}")]
62 EntityTypeConfictError {
63 /// String representation of PARC
64 id: SmolStr,
65 /// Existing value of PARC
66 existing_value: EntityType,
67 /// The provided value
68 given_value: Value,
69 },
70 /// Errors that occur when evaluating partial values
71 #[error(transparent)]
72 #[diagnostic(transparent)]
73 ValueEval(#[from] EvaluationError),
74}
75
76/// Errors that occur during reauthorizing partial responses
77#[derive(Debug, Error, Diagnostic)]
78pub enum ReauthorizationError {
79 /// Errors that occur during re-constructing policy sets
80 #[error(transparent)]
81 #[diagnostic(transparent)]
82 PolicySetError(#[from] PolicySetError),
83 /// Errors that occur during concretizing a partial request
84 #[error(transparent)]
85 #[diagnostic(transparent)]
86 ConcretizationError(#[from] ConcretizationError),
87}