Skip to content

fix(compiler-cli): report diagnostic instead of crashing on malformed…#69441

Open
aparzi wants to merge 1 commit into
angular:mainfrom
aparzi:fix-angular-language-service-69106
Open

fix(compiler-cli): report diagnostic instead of crashing on malformed…#69441
aparzi wants to merge 1 commit into
angular:mainfrom
aparzi:fix-angular-language-service-69106

Conversation

@aparzi

@aparzi aparzi commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

parseHostBindings throws plain Errors for malformed host bindings (e.g. a property binding with a non-static value, as can happen while editing in the language service). These were uncaught during directive analysis, crashing the compiler and the Angular Language Service.

Wrap the call and surface the error as a FatalDiagnosticError so it becomes a diagnostic and analysis can complete normally.

Fixes #69106

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

Issue Number: #69106

Does this PR introduce a breaking change?

  • Yes
  • No

… host binding

`parseHostBindings` throws plain `Error`s for malformed host bindings
(e.g. a property binding with a non-static value, as can happen while
editing in the language service). These were uncaught during directive
analysis, crashing the compiler and the Angular Language Service.

Wrap the call and surface the error as a `FatalDiagnosticError` so it
becomes a diagnostic and analysis can complete normally.

Fixes angular#69106
@pullapprove pullapprove Bot requested a review from crisbeto June 19, 2026 10:53
@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Jun 19, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jun 19, 2026
@@ -337,8 +337,11 @@ export class IncrementalCompilation implements IncrementalBuild<ClassRecord, Fil
}

priorTypeCheckingResultsFor(sf: ts.SourceFile): FileTypeCheckingData | null {
// In some environments (e.g., language service during edits), type-check queries can occur

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure about the implications of this on the language service. cc @atscott

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm well certainly errors are never good for language service if not caught but this seems like a suspicious place to fix it. Probably needs something higher up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback!

Looking "higher up" in the stack, analyzeTrait in packages/compiler-cli/src/ngtsc/transform/src/compilation.ts already wraps trait.handler.analyze() in a try/catch, but it only handles FatalDiagnosticError and re-throws everything else. That re-throw is what actually propagates up and crashes the Language Service.

Would the right direction be to generalize that catch so any unexpected error during directive analysis becomes a diagnostic instead of being re-thrown? That would protect the LS from this and similar future bugs in any handler, not just host-bindings. Happy to update the PR to take that approach if it sounds right to you.

@crisbeto crisbeto requested a review from atscott June 19, 2026 13:28
try {
bindings = parseHostBindings(hostMetadata);
} catch (e) {
// `parseHostBindings` throws plain `Error`s for malformed bindings (e.g. `'[class.has-]'`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment isn’t needed, please remove.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also seems a bit of an odd choice. Why not change the parsing function to throw fatal diagnostics instead of plain errors if it’s not allowed to throw errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anglar Language Service (vscode) crash when modify component's host property for host binding.

3 participants