Skip to content

fix(diff): surface parser failures instead of empty ValidationError (fixes #2222) - #2313

Open
abhinavkdeval08-design wants to merge 6 commits into
asyncapi:masterfrom
abhinavkdeval08-design:fix/diff-empty-validation-error
Open

abhinavkdeval08-design wants to merge 6 commits into
asyncapi:masterfrom
abhinavkdeval08-design:fix/diff-empty-validation-error

Conversation

@abhinavkdeval08-design

Copy link
Copy Markdown

Description

This PR fixes an issue where running asyncapi diff with a malformed or unparsable document exited with code 1 and printed a bare, empty ValidationError: without any diagnostic error message.

Root Cause

  1. Incorrect Error Type: The parseDocuments function in src/apps/cli/commands/diff.ts was constructing a ValidationError with type: 'invalid-file', which is intended for missing files and ignores the err payload entirely. It has been corrected to use 'parser-error'.
  2. Double-Wrapping & Empty Fallback: The outer catch block in run() was wrapping unknown errors into a new ValidationError without checking if the caught error was already a ValidationError. Additionally, buildError evaluated to an empty string when encountering plain string errors or generic error shapes.

Changes Proposed

  • Updated src/apps/cli/commands/diff.ts to use type: 'parser-error' in parseDocuments.
  • Added error instanceof ValidationError pass-through check in run()'s catch block to prevent double-wrapping.
  • Added safe optional chaining and a robust fallback handler inside src/errors/validation-error.ts's buildError method to properly surface plain strings and error messages.

Testing

  • Verified locally with test fixtures:
    ./bin/run_bin diff test/fixtures/specification.yml test/fixtures/specification-invalid.yml

…ixes asyncapi#2222)

Signed-off-by: Abhinav Deval <abhinavkdeval08@gmail.com>
@changeset-bot

changeset-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 31ddbb5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot left a comment

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.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@abhinavkdeval08-design
abhinavkdeval08-design force-pushed the fix/diff-empty-validation-error branch from c7e4a83 to 051343e Compare October 10, 2026 17:22
Signed-off-by: Abhinav Deval <abhinavkdeval08@gmail.com>
@abhinavkdeval08-design

Copy link
Copy Markdown
Author

Update:

  • Added the required changeset for @asyncapi/cli (patch)[cite: 1].
  • All local tests, parser error fixture verifications, and SonarCloud checks are passing cleanly[cite: 1].

PTAL whenever you have bandwidth! 🙏
cc: @princerajpoot20, @Souvikns

@abhinavkdeval08-design

Copy link
Copy Markdown
Author

Hi team! 👋

Just a quick update on this PR:

  • Status: All local checks, parser error fixture verifications, and SonarCloud Quality Gate checks are passing cleanly
  • Changeset: Included for @asyncapi/cli patch release.
  • Fix Summary: Corrects the error type to parser-error in src/apps/cli/commands/diff.ts, prevents double-wrapping of ValidationError in run(), and enhances buildError inside src/errors/validation-error.ts to properly surface plain strings and diagnostic messages.

Whenever you have some bandwidth, could you please review and take a look?

cc: @Souvikns, @princerajpoot20

@sonarqubecloud

Copy link
Copy Markdown

@abhinavkdeval08-design

Copy link
Copy Markdown
Author

Merged latest master and resolved the conflicts in src/apps/cli/commands/diff.ts, keeping the centralized ApplicationError (DOCUMENT_PARSE_FAILED) flow while passing type: 'parser-error' to ValidationError so parser diagnostics surface properly instead of an empty message.

Checks and the changeset are in place. Could you take a look when you get a chance? cc @Souvikns @princerajpoot20

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

Labels

None yet

Projects

Status: To Triage

Development

Successfully merging this pull request may close these issues.

1 participant