asyncapi / asyncapi/cli

[BUG] Generator attempts to submit anonymous metrics even after fatal generation failure

Open
#2,010 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
272
Forks
375
Avg merge
3h 22m
Merged PRs (30d)
8

Description

### Describe the bug.

The AsyncAPI Generator attempts to submit anonymous usage metrics even after generation has already failed with a fatal error. This results in an additional runtime error being printed, which is unrelated to the actual cause of the failure and pollutes the output.

Metrics submission should only occur after a successful generation or a clean shutdown, not after a hard failure.

### Expected behavior

- Generation should abort immediately after a fatal error.
- No attempt should be made to submit anonymous metrics.
- No secondary or unrelated errors should be printed.

### Screenshots

Image

### How to Reproduce

1. Create a non-empty output directory:
```bash
mkdir out
echo test > out/file.txt
```
2. Use the following AsyncAPI document:
```
asyncapi: '2.6.0'
info:
title: Metrics Failure Test
version: '1.0.0'
channels: {}
```
3. Run the generator:
```
asyncapi generate asyncapi.yaml @asyncapi/html-template --output ./out
```
4. Current Behavior
The generator fails as expected due to the non-empty output directory, but then prints an additional error related to metrics submission:
```
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
```

### 🖥️ Device Information [optional]

- Operating System (OS):Windows(WSL)
- Browser:
- Browser Version:

### 👀 Have you checked for similar open issues?

- [x] I checked and didn't find similar issue

### 🏢 Have you read the Contributing Guidelines?

- [x] I have read the [Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)

### Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.