Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Test branch release/2.4.x #287

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions cedar-policy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "cedar-policy-cli"
edition = "2021"

version = "2.3.3"
version = "2.4.0"
license = "Apache-2.0"
categories = ["compilers", "config"]
description = "CLI interface for the Cedar Policy language."
Expand All @@ -11,15 +11,13 @@ homepage = "https://cedarpolicy.com"
repository = "https://github.com/cedar-policy/cedar"

[dependencies]
cedar-policy = { version = "=2.3.3", path = "../cedar-policy" }
cedar-policy-formatter = { version = "=2.3.3", path = "../cedar-policy-formatter" }
clap = { version = "4", features = ["derive"] }
cedar-policy = { version = "=2.4.0", path = "../cedar-policy" }
cedar-policy-formatter = { version = "=2.4.0", path = "../cedar-policy-formatter" }
clap = { version = "4", features = ["derive", "env"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"

[features]
default = []
miette = { version = "5.9.0", features = ["fancy"] }
thiserror = "1.0"

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
39 changes: 39 additions & 0 deletions cedar-policy-cli/src/err.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use std::error::Error;

use miette::{Diagnostic, Report};
use thiserror::Error;

/// Internal adapter from Rust's standard [`Error`] to [`miette`]'s
/// [`Diagnostic`], with an attached diagnostic code.
#[derive(Debug, Diagnostic, Error)]
#[error(transparent)]
#[diagnostic(code(cedar_policy_cli::other_err))]
struct DiagnosticError(Box<dyn Error + Send + Sync + 'static>);

/// Alternative to [`miette::IntoDiagnostic`] which attaches diagnostic codes
/// to adapted [`Error`]s for better-formatted output.
pub trait IntoDiagnostic<T, E> {
fn into_diagnostic(self) -> Result<T, Report>;
}

impl<T, E: Error + Send + Sync + 'static> IntoDiagnostic<T, E> for Result<T, E> {
fn into_diagnostic(self) -> Result<T, Report> {
self.map_err(|err| DiagnosticError(Box::new(err)).into())
}
}
Loading
Loading