Skip to content

fix: suppress anonymous metrics submission after fatal generation errors#2069

Closed
chengyixu wants to merge 1 commit intoasyncapi:masterfrom
chengyixu:fix/2010-suppress-metrics-error-on-failure
Closed

fix: suppress anonymous metrics submission after fatal generation errors#2069
chengyixu wants to merge 1 commit intoasyncapi:masterfrom
chengyixu:fix/2010-suppress-metrics-error-on-failure

Conversation

@chengyixu
Copy link

Summary

Fixes #2010 — When a fatal generation error occurs (e.g. non-empty output directory), the CLI attempted to flush anonymous metrics and printed an unrelated error to stdout:

Generator Error: "./out" is not an empty directory. You might override your work.
Skipping submitting anonymous metrics due to the following error: TypeError: fetch failed

The second line is confusing — it looks like a second failure but it's just a metrics network call that failed during the error path.

Root Cause

finally() in base.ts is always called by oclif, even after fatal errors. It unconditionally called recordActionFinished(), which tried to flush metrics to the network. When that network call failed (e.g. in CI or offline), the error was caught and printed to stdout, polluting the user-facing error output.

Fix

Skip metrics submission entirely when error is defined (i.e. the command exits with a fatal error):

// Skip metrics on fatal errors to avoid printing unrelated network errors. #2010
if (error !== undefined) {
  return;
}

This is correct behaviour — the metricsMetadata['success'] is still set to false before the early return (for consistency), but no network call is made.

Changes

  • src/apps/cli/internal/base.ts: Guard recordActionFinished() with an early return when error is defined

Test Plan

  • Existing tests pass (no regressions)
  • Manual: asyncapi generate asyncapi.yaml @asyncapi/html-template --output ./non-empty-dir no longer prints the metrics error message

🤖 Generated with Claude Code

When a fatal error occurred (e.g. non-empty output directory), the CLI
attempted to flush metrics and printed an unrelated
'Skipping submitting anonymous metrics due to …' error to stdout,
polluting the output. Metrics are now skipped entirely when the command
exits with an error.

Fixes asyncapi#2010
@changeset-bot
Copy link

changeset-bot bot commented Mar 21, 2026

🦋 Changeset detected

Latest commit: f29f0c6

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

@sonarqubecloud
Copy link

@chengyixu
Copy link
Author

Hi @asyncapi/cli-maintainers! All CI checks are passing for this PR. Happy to make any adjustments needed for merge. Thanks!

@github-project-automation github-project-automation bot moved this from To Triage to Done in CLI - Kanban Mar 23, 2026
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] Generator attempts to submit anonymous metrics even after fatal generation failure

2 participants