cedar-policy / cedar

Implementation of the Cedar Policy Language
https://www.cedarpolicy.com
Apache License 2.0
889 stars 80 forks source link

Improve parse error for `is <string-lit>` #1252

Open john-h-kastner-aws opened 1 month ago

john-h-kastner-aws commented 1 month ago

Before opening, please confirm:

Bug Category

Cedar Parser

Describe the bug

Parsing the policy permit(principal, action, resource) when { principal is "User" }; gives the error

[jkastner@dev-dsk-jkastner-1a-3309db3b cedar]$ cargo run -q check-parse <<<'permit(principal, action, resource) 
when { principal is "User" };'
  × failed to parse policy set
  ╰─▶ right hand side of an `is` expression must be an entity type name, but got `User`
   ╭────
 1 │ permit(principal, action, resource) when { principal is "User" };
   ·                                                         ──────
   ╰────
  help: try using `==` to test for equality

This error should be more useful:

  1. In the message text User should be rendered as a string "User"
  2. The try using `==` to test equality help text is not so useful because in this case it's just a likely that they meant to drop the quotes for principal is User.

Expected behavior

.

Reproduction steps

.

Code Snippet

// Put your code below this line.

Log output

// Put your output below this line

Additional configuration

No response

Operating System

No response

Additional information and screenshots

No response