Skip to content

fix(diff): surface parser failures instead of an empty ValidationError - #2339

Open
hondammy81 wants to merge 4 commits into
asyncapi:masterfrom
hondammy81:fix/diff-empty-validation-error
Open

hondammy81 wants to merge 4 commits into
asyncapi:masterfrom
hondammy81:fix/diff-empty-validation-error

Conversation

@hondammy81

Copy link
Copy Markdown

Fixes #2222

What

asyncapi diff exits with code 1 and prints a bare ValidationError: with no diagnostic body when one of the supplied documents fails to parse. This PR makes the command surface the actual parse failure instead. It revives the approach from #2223, which was closed by its author without merging.

Why

Two bugs in the parser-failure path combine to swallow the error, as analysed in #2222:

  1. parseDocuments in src/apps/cli/commands/diff.ts built the error with type invalid-file, which is the file-not-found template. It ignores the parse error entirely. The catch block in run() in the same file already uses parser-error for the same kind of failure, so this was an inconsistency.
  2. buildError in src/errors/validation-error.ts only read the ParserError fields (title, detail, validationErrors). The validation service reports parse failures as a plain string (Failed to parse document), and the run() catch block wraps the first ValidationError in a second one. Both shapes produced an empty message, so oclif printed ValidationError: and nothing else.

How

  • Switch the parseDocuments failure branch from invalid-file to parser-error.
  • In buildError, keep the existing ParserError formatting exactly as it was, and add a fallback for shapes with no ParserError fields: use the string itself when the error is a string, otherwise the wrapped error's message, otherwise a fixed Unknown parser error. The per-entry formatting moved into a small helper so the function stays within the project's cognitive-complexity lint threshold.
  • One pre-existing unit test asserted the empty message for a parser error with no details. That assertion encoded the bug, so it now asserts the fallback message instead.

Testing

Reproduced against the fixtures shipped in the repo, before and after:

# before
$ ./bin/run_bin diff test/fixtures/specification.yml test/fixtures/specification-invalid.yml
ValidationError:
$ echo $?
1

# after
$ ./bin/run_bin diff test/fixtures/specification.yml test/fixtures/specification-invalid.yml
ValidationError: Failed to parse document
$ echo $?
1
  • test/unit/errors/errors.test.ts: 30 passing. New cases cover the string error the validation service returns, a generic Error, a wrapped ValidationError (the run() catch path), and an undefined error.
  • test/integration/diff.test.ts: 27 passing, including a new case asserting the parse failure reaches stderr with its message.
  • Full unit tree (test/unit/**): 244 passing.
  • npm run build clean, and eslint reports no errors or warnings on the changed files.

Out of scope

Surfacing the parser's full diagnostics (which rule failed, with line and column) would require the validation service to stop reducing parse failures to a single string. That is a larger change to the service result shape and is left as a follow-up.

Generated-by: Muse Spark 1.3
/

@changeset-bot

changeset-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 08c6d4f

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.

@sonarqubecloud

sonarqubecloud Bot commented Nov 8, 2026

Copy link
Copy Markdown

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.

[BUG] asyncapi diff prints empty ValidationError: on parse failure

1 participant