Skip to content

Conversation

adpaco-aws
Copy link
Contributor

Description of changes

This PR extends unknown function errors with a hint that suggests the closest function from the ones available based on the fuzzy string matching algorithm used to make similar suggestions. With this change, the example in #332 now also shows the help message Did you mean `ip`? in its diagnostics.

Resolves #332

Callouts

This PR does not deal with #246, a similar request for methods instead of functions. But I'm planning on fixing it right after this one's cleared.

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A bug fix or other functionality change requiring a patch to cedar-policy.

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.

Signed-off-by: Adrian Palacios <accorell@amazon.com>
Signed-off-by: Adrian Palacios <accorell@amazon.com>
Signed-off-by: Adrian Palacios <accorell@amazon.com>
Signed-off-by: Adrian Palacios <accorell@amazon.com>
#[error("`{0}` is not a valid function")]
UnknownFunction(ast::Name),
#[error("`{id}` is not a valid function")]
UnknownFunction {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a note for other reviewers: while including the fields directly on the variant isn't generally our convention, the ToASTErrorKind enum is not publicly exported, and other variants on the enum use the same setyle.

Signed-off-by: Adrian Palacios <accorell@amazon.com>
Signed-off-by: Adrian Palacios <accorell@amazon.com>
Signed-off-by: Adrian Palacios <accorell@amazon.com>
@adpaco-aws adpaco-aws merged commit 8ab5dae into cedar-policy:main Oct 23, 2024
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fuzzy match on non-existing extension functions
3 participants