Skip to content

fix(context): clean up error checks and dead code in config context commands - #2312

Open
viky-01 wants to merge 2 commits into
asyncapi:masterfrom
viky-01:fix/context-error-checks
Open

viky-01 wants to merge 2 commits into
asyncapi:masterfrom
viky-01:fix/context-error-checks

Conversation

@viky-01

@viky-01 viky-01 commented Oct 6, 2026

Copy link
Copy Markdown

Description

Across all six config context commands (add, current, edit, list, remove, and use), error handling previously checked:

if (e instanceof (MissingContextFileError || ContextFileWrongFormatError)) {
  this.error(`Unable to ... You have no context file configured. Run asyncapi config context init to initialize it.`);
}

Because (MissingContextFileError || ContextFileWrongFormatError) evaluates first in JavaScript and MissingContextFileError (a class constructor) is truthy, the expression always evaluates to MissingContextFileError, leaving ContextFileWrongFormatError un-evaluated.

This PR cleans up this construct and adds missing negative tests:

  1. Replaces e instanceof (MissingContextFileError || ContextFileWrongFormatError) with e instanceof MissingContextFileError in all six commands (add.ts, current.ts, edit.ts, list.ts, remove.ts, use.ts).
  2. Removes unused ContextFileWrongFormatError imports across all six commands.
  3. In current.ts, removes the dead check || (fileContent && !fileContent.current) inside the catch (e) block where fileContent is always undefined.
  4. Adds negative integration tests in test/integration/context.test.ts for current, list, edit, use, and remove with a malformed context file to verify that ContextError: Context file "..." has wrong format. is cleanly emitted.

Related issue(s)

Fixes #2311

…xt commands (asyncapi#2311)

- Fix operator precedence bug in instanceof expression across all 6 context commands
- Remove unused ContextFileWrongFormatError imports
- Remove unreachable (fileContent && !fileContent.current) check in current.ts
- Add negative integration tests for current, list, edit, use, and remove when context file is malformed
@changeset-bot

changeset-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 81f75ae

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a 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 2, 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.

[FEATURE] Clean up the error checks in the config context commands

2 participants