cedar_policy_core/transitive_closure/err.rs
1/*
2 * Copyright 2022-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
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 std::fmt::Debug;
18use std::fmt::Display;
19use thiserror::Error;
20
21/// Error type for errors raised during transitive closure computation. This
22/// error type is parametrized by a type `K` which is the type of a unique
23/// identifier for graph nodes and the type returned by `get_key` on the
24/// `TCNode` trait.
25#[derive(Debug, Error)]
26pub enum Err<K: Debug + Display> {
27 /// Error raised when `TCComputation::EnforceAlreadyComputed` finds that the
28 /// TC was in fact not already computed
29 #[error("expected all transitive edges to exist, but they don't. {child} is a child of {parent} is a child of {grandparent}, but {grandparent} is not marked as an ancestor of {child}")]
30 TCEnforcementError {
31 /// Child entity at fault
32 child: K,
33 /// Parent entity at fault
34 parent: K,
35 /// Grandparent entity at fault. This is a parent of `parent` but not an
36 /// ancestor of `child`.
37 grandparent: K,
38 },
39 /// Error raised when enforce_dag finds that the graph is not a DAG
40 #[error("input graph has a cycle. Vertex {} has a loop.", .vertex_with_loop)]
41 HasCycle {
42 /// Because DAG enforcement can only be called after compute_tc/enforce_tc, a cycle will manifest as a vertex with a loop
43 vertex_with_loop: K,
44 },
45}
46
47/// Type alias for convenience
48pub type Result<T, K> = std::result::Result<T, Err<K>>;