Skip to content

More useful (or less confusing) parse errors on unexpected token #176

@john-h-kastner-aws

Description

@john-h-kastner-aws

Category

Other

Describe the feature you'd like to request

An unexpected token causes the parser to emit an error message listing every token in would have accepted in that position.

E.g., on permit(principal, action, resource; (missing the closing paren) the error text is

Error: cedar_policy_core::parser::to_cst_error

  × unexpected token `;`
   ╭─[a.cedar:1:1]
 1 │ permit(principal, action resource;
   ·                                  ┬
   ·                                  ╰── expected `!=`, `%`, `&&`, `(`, `)`, `*`, `+`, `,`, `-`, `.`, `/`, `:`, `::`, `<`, `<=`, `==`, `>`, `>=`, `[`, `]`, `{`, `||`, `}`, `else`, `has`, `in`, `like`, or `then`
   ╰────

The list of expected tokens isn't helpful, and potentially makes the error more confusing that it would be otherwise.

This was brought up recently due to a schema parsing error in #149 where this sort of overly verbose error was caused by an empty string used for an entity type name.

Some solutions that come to mind:

  • Expand what tokens the parer expects so that more error reporting can be handled in CST -> AST conversion where we have full control over error messages and can inspect the surrounding CST to generate better errors.
  • Restrict what tokens the parser expects so that there will be fewer tokens in the expected tokens list.
  • Hide the long token lists. Maybe they're confusing enough that it makes sense to hide it altogether.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestThis issue requets a substantial new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions