Skip to content

Cedar VS Code extension crashes on format/validate when annotation text contains standalone "Action" #45

@kilakewe

Description

@kilakewe

Before opening, please confirm:

Bug Category

Cedar Policy Editing

Describe the bug

Formatting and validation crash in the Cedar VS Code extension when an annotation string contains the standalone word Action. The extension throws a TypeError and the formatting provider fails.

From the stack trace, the crash occurs while parsing policy text and trying to read length from an undefined value. This appears to happen when Action in annotation text is interpreted as an action type token without an action id.

Expected behavior

Formatting and validation should succeed regardless of annotation label text. Annotation strings should not be parsed as policy entity/action references.

Reproduction steps

  1. Open a Cedar policy file in VS Code.
  2. Add a policy annotation containing standalone Action text, for example:
  3. @id("Example Action Policy")
  4. Include a normal policy body under it.
  5. Run Format Document (or trigger validation).
  6. See extension error and failed formatting provider.

Code Snippet

@id("Example Action Policy")
permit (
  principal is App::User,
  action == App::Action::"example",
  resource is App::Sample
);

A workaround that avoids the crash:

@id("Example Alternative Policy")

Log output

2026-03-18 13:05:38.308 [error] [cedar-policy.vscode-cedar] provider FAILED
2026-03-18 13:05:38.309 [error] TypeError: Cannot read properties of undefined (reading 'length')
at .../out/parser.js:170:68
at Array.forEach (<anonymous>)
at parseCedarPoliciesDoc (.../out/parser.js:162:20)
at validateCedarDoc (.../out/validate.js:202:52)
at Object.provideDocumentFormattingEdits (.../out/extension.js:261:19)
2026-03-18 13:05:39.330 [error] TypeError: Cannot read properties of undefined (reading 'length')
at .../out/parser.js:170:68
at Array.forEach (<anonymous>)
at parseCedarPoliciesDoc (.../out/parser.js:162:20)
at validateCedarDoc (.../out/validate.js:202:52)

Additional configuration

No response

Visual Studio Code version

Version: 1.111.0 Commit: ce099c1ed25d9eb3076c11e4a280f3eb52b4fbeb

Cedar policy language extension version

0.10.2

Additional information and screenshots

Likely root cause: parser token matching is not ignoring annotation string literals, and standalone Action text is treated like an action type reference without an id.
Suggested fix: guard against missing id before reading length, and/or skip scanning annotation string literals for entity/action references.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions