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

[BUG] Inaccurate error in asyncapi optimize #1626

Open
2 tasks done
derberg opened this issue Jan 14, 2025 · 3 comments
Open
2 tasks done

[BUG] Inaccurate error in asyncapi optimize #1626

derberg opened this issue Jan 14, 2025 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@derberg
Copy link
Member

derberg commented Jan 14, 2025

Describe the bug.

I have AsyncAPI document with broken message reference in line 39:

asyncapi: 3.0.0

info:
  title: Account Service
  version: 1.0.0
  description: This service is in charge of processing user signups

servers: 
  development:
    host: loca{dupa}lhost:5672
    description: Development AMQP broker.
    protocol: amqp
    protocolVersion: 0-9-1

  staging:
    host: rabbitmq-staging.in.mycompany.com:5672
    description: RabbitMQ broker for the staging environment.
    protocol: amqp
    protocolVersion: 0-9-1

  production:
    host: rabbitmq.in.mycompany.com:5672
    description: RabbitMQ broker for the production environment.
    protocol: amqp
    protocolVersion: 0-9-1

channels:
  userSignedup:
    address: user/signedup
    messages:
      UserSignedUp:
        $ref: '#/components/messages/UserSignedUp'
operations:
  sendUserSignedup:
    action: send
    channel:
      $ref: '#/channels/userSignedup'
    messages:
      - $ref: '#/components/messages/UserSignedUp'
components:
  messages:
    UserSignedUp:
      payload:
        type: object
        properties:
          displayName:
            type: string
            description: Name of the user
          email:
            type: string
            format: email
            description: Email of the user

When I run: asyncapi optimize ./asyncapi-client.yaml I get error like

[
  {
    code: 'asyncapi3-operation-messages-from-referred-channel',
    message: 'Operation message does not belong to the specified channel.',
    path: [ 'operations', 'sendUserSignedup', 'messages', '0' ],
    severity: 0,
    range: { start: [Object], end: [Object] }
  }
]
ValidationError: There is no file or context with name "./asyncapi-client.yaml".

The array with validation error info is correct. I mean, maybe object should be rendered instead of [Object] but in general it is ok.

The problem is with the last line:
ValidationError: There is no file or context with name "./asyncapi-client.yaml".

This error just doesn't make sense, the path reference was correct, otherwise validation would not catch the error with the message

Expected behavior

Remove the misleading error message

Screenshots

no

How to Reproduce

already described in description

🥦 Browser

None

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

No, someone else can work on it

@derberg derberg added the bug Something isn't working label Jan 14, 2025
@github-project-automation github-project-automation bot moved this to To Triage in CLI - Kanban Jan 14, 2025
@Yashgupta9330
Copy link

@derberg I believe the issue is related to a validation error, which is causing the misleading "file not found" message. I'd like to work on this and resolve the issue. Can you please assign it to me?

@Ervishalpathak7
Copy link
Contributor

Ervishalpathak7 commented Mar 4, 2025

Fixing Misleading Validation Error in AsyncAPI CLI

Hello @derberg, @AayushSaini101

I’ve investigated the error you described, traced through the code, and identified the root cause. Let me walk you through the fix! 🚀

🧩 Problem

In the error report, the CLI threw this misleading message:

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

However, the validation already caught other issues, meaning the file path was correct. The misleading message originated from this 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,
    })
  );
}

In the catch block, the code throws a ValidationError of type 'invalid-file', even though the file existed and the error came from parsing.

Solution

I changed the error type from 'invalid-file' to 'parser-error', so the actual parsing errors are properly surfaced:

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

This way, instead of falsely claiming the file doesn’t exist, the CLI will display detailed parsing errors — giving users accurate feedback! 🎯

🔧 Result

With this fix, the CLI now correctly shows parser-related errors, helping users debug their AsyncAPI specs more effectively.

I’ve pushed the fix and raised a PR. Could you please review it when you have a moment? 🙌

Thanks so much!


Let me know if you’d like me to tweak the wording or add anything! ✌️

Ervishalpathak7 added a commit to Ervishalpathak7/async-cli that referenced this issue Mar 4, 2025
Ervishalpathak7 added a commit to Ervishalpathak7/async-cli that referenced this issue Mar 5, 2025
Ervishalpathak7 added a commit to Ervishalpathak7/async-cli that referenced this issue Mar 7, 2025
@neoandmatrix
Copy link
Contributor

@AayushSaini101 This issue has been resolved by the PR #1634 and can be close successfully.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Status: To Triage
Development

Successfully merging a pull request may close this issue.

5 participants