Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Inaccurate error in asyncapi optimize #1626 #1688

Conversation

Ervishalpathak7
Copy link
Contributor

@Ervishalpathak7 Ervishalpathak7 commented Mar 4, 2025

fix #1626 Fix misleading ValidationError message for valid file paths

Description:

Hello @derberg,

I’ve investigated the issue with the misleading error message, and here’s what I found:

Problem:

When running the command:

asyncapi optimize ./asyncapi-client.yaml

Even with a valid file path, an incorrect error message appeared:

ValidationError: There is no file or context with name "./asyncapi-client.yaml".

After debugging, I found that the issue lies in the following code section:

let optimizer: Optimizer;
let report: Report;
try {
  optimizer = new Optimizer(this.specFile.text());
  report = await optimizer.getReport();
} catch (err) {
  this.error(
    new ValidationError({
      type: 'invalid-file',
      filepath: filePath,
    })
  );
}

Root Cause:

The catch block throws a ValidationError with type invalid-file, which causes the misleading message about the file not existing — even when the file is valid but contains parsing issues.

Fix:

I changed the error type from invalid-file to parser-error. This way, the ValidationError will provide more accurate and detailed parsing error messages instead of falsely indicating a missing file.

catch (err) {
  this.error(
    new ValidationError({
      type: 'parser-error',
      err: err,
    })
  );
}

With this change, users will see the actual parsing errors, making debugging much easier!

I’ve pushed the fix and raised a PR. Could you please review it? Let me know if you’d like any adjustments.

Thanks! 🚀

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Mar 4, 2025

We require all PRs to follow Conventional Commits specification.
More details 👇🏼

 No release type found in pull request title "Fixed Inaccurate error in asyncapi optimize #1626". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

Copy link
Contributor

@github-actions github-actions bot left a comment

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.

Copy link

sonarqubecloud bot commented Mar 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BUG] Inaccurate error in asyncapi optimize
2 participants