-
Notifications
You must be signed in to change notification settings - Fork 83
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
Consistency pass over error messages #327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor suggestions/nitpicks
@@ -778,7 +778,7 @@ impl std::str::FromStr for Expr { | |||
#[derive(Debug, Clone, Error)] | |||
pub enum SubstitutionError { | |||
/// The supplied value did not match the type annotation on the unknown. | |||
#[error("Expected a value of type {expected}, got a value of type {actual}")] | |||
#[error("expected a value of type {expected}, got a value of type {actual}")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the {expected} and {actual} types be surrounded with backticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been surrounding types with backticks -- see my comment below.
@@ -212,7 +212,7 @@ impl std::error::Error for TypeError {} | |||
pub enum TypeErrorKind { | |||
/// The typechecker expected to see a subtype of one of the types in | |||
/// `expected`, but saw `actual`. | |||
#[error("Unexpected type. Expected {} but saw {}", | |||
#[error("unexpected type: expected {} but saw {}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should types be surrounded with backticks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided not to surround types with backticks since they are not verbatim user input, and I felt that expected bool but saw string
was just as clear as expected `bool` but saw `string`
. Open to second opinions.
Note: Your comment made me realize that we weren't following the rules when printing types (we were printing entity of type Foo
rather than entity of type `Foo`
). Fixing this required changing a bunch of the corpus tests, which is why the diff in my recent commit is so large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, here is how we currently print types:
bool
long
string
set
record
(entity of unspecified type)
(entity of type `Foo`)
whereFoo
is some user-specified name
Description of changes
Another pass at standardizing error messages. My changes are meant to align with the following rules (loosely inspired by https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-structure):
wrong number of arguments in extension function application. Expected {}, got {}
(note the initial lowercase letter and lack of final period).undeclared action `foo`
,undeclared entity type(s): {"Foo"}
error occurred while evaluating policy `policy0`: `User::\"alive\"` does not have the attribute `foo`
Issue #, if available
Checklist for requesting a review
The change in this PR is (choose one, and delete the other options):
cedar-policy-core
,cedar-validator
, etc.)I confirm that this PR (choose one, and delete the other options):
I confirm that
cedar-spec
(choose one, and delete the other options):Disclaimer
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.