-
Notifications
You must be signed in to change notification settings - Fork 107
add source locations to evaluation errors #582
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
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.
Looks good. I don't see anything that looks like a breaking change
error_kind: EvaluationErrorKind, | ||
/// Optional advice on how to fix the error | ||
advice: Option<String>, | ||
/// Source location of the error. (This overrides other sources if present, |
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.
This seems error-prone to me. Maybe create an issue to fix it?
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.
Happy to create an issue, curious what you find to be error-prone about this?
Are you concerned that the source location in this field might disagree with the source location embedded in error_kind
? If it makes you feel better, the vast majority of the EvaluationErrorKind
s do not have a source loc field -- the only cases that do have a source loc are InvalidRestrictedExpression
and NonValue
, and those just because they store an Expr
as part of the error. We could make an issue to remove these somehow, so that error_kind
never contains a source loc; is that what you're suggesting?
Going the other way -- having all the source locs in error_kind
so that we never need this field -- is backwards; we established recently that we prefer the convention to use the *Kind
pattern to have a single place the source loc field is defined, rather than adding a source loc field in N places, once for each enum variant. The struct here conforms to that practice.
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.
Yeah, it's just a general concern about "code smell," not anything concrete. Even if we always remember to keep them in sync, I'd worry about that complexity hiding other bugs. E.g., I think the bug we had where it was possible to add a link and a template with colliding names wouldn't have happened if we didn't have duplicate information in our lists of policies+templates and links+templates. Even though it wasn't caused by forgetting to keep data in sync, the added complexity (e.g., rolling back changes to one representation if modifying the other failed) distracts code reviewers from the obvious "you forgot to check that no link with this ID exists."
Signed-off-by: Katherine Hough <[email protected]>
Description of changes
Source locations for evaluation errors.
I think the required changes to
EvaluationError
manage to be non-breaking --EvaluationError
is a public type, but its fields are private, this PR doesn't change theEvaluationErrorKind
enum, and the constructors I changed are all markedpub(crate)
. But someone should check me on this.(I did remove two
From
impls, which can be added back if necessary. But they should be deprecated in favor of the new constructors which also take a source location.)Issue #, if available
Towards resolving #485. (Just evaluation errors, not the entity-parsing errors or other errors also mentioned in #485.)
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.