Skip to main content

cedar_policy_symcc/
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
17//! All error types in SymCC.
18
19use cedar_policy_core::validator::ValidationError;
20use miette::Diagnostic;
21use thiserror::Error;
22
23pub use crate::symcc::{
24    ext::ExtError, extension_types::datetime::DatetimeError,
25    extension_types::decimal::DecimalError, extension_types::ipaddr::IPError, term::Term,
26    BitVecError, CompileError, ConcretizeError, DecodeError, EncodeError, SolverError,
27};
28
29/// Top-level errors from the whole `cedar-policy-symcc` crate.
30#[derive(Debug, Diagnostic, Error)]
31pub enum Error {
32    /// Action not found in schema.
33    #[error("action not found in schema: {0}")]
34    ActionNotInSchema(String),
35    /// Errors during symbolic compilation.
36    #[error("symbolic compilation failed: {0}")]
37    CompileError(#[from] CompileError),
38    /// Errors from the SMT encoder.
39    #[error("failed to encode SMT terms: {0}")]
40    EncodeError(#[from] EncodeError),
41    /// Solver-related errors.
42    #[error(transparent)]
43    SolverError(#[from] SolverError),
44    /// Solver returned `unknown`.
45    #[error("solver returned `unknown`")]
46    SolverUnknown,
47    /// Policy is not well-typed.
48    #[error("input policy (set) is not well typed with respect to the schema")]
49    PolicyNotWellTyped {
50        /// Errors from the policy validator.
51        #[related]
52        errs: Vec<ValidationError>,
53    },
54    /// Failed to decode the SMT model.
55    #[error("failed to decode model: {0}")]
56    DecodeModel(#[from] DecodeError),
57    /// Errors during concretization.
58    #[error("failed to recover a concrete counterexample: {0}")]
59    ConcretizeError(#[from] ConcretizeError),
60    /// Model successfully decoded and concretized, but the resulting model is invalid.
61    #[error("model is invalid: violates assertion {assert}")]
62    ModelInvalid {
63        /// Assertion that was violated
64        assert: Term,
65    },
66    /// Empty-list of policies was passed to a function that expects at least one policy
67    #[error("expected to have at least one policy")]
68    NoPolicies,
69}
70
71/// A result type that potentially returns a SymCC [`enum@Error`].
72pub type Result<T> = std::result::Result<T, Error>;