Skip to content

fix(logger): remove unused config dependency and directory creation - #2324

Open
joshi-07 wants to merge 3 commits into
asyncapi:masterfrom
joshi-07:fix/remove-unused-logger-config-warnings
Open

joshi-07 wants to merge 3 commits into
asyncapi:masterfrom
joshi-07:fix/remove-unused-logger-config-warnings

Conversation

@joshi-07

@joshi-07 joshi-07 commented Oct 16, 2026 •

Copy link
Copy Markdown

Description

Running CLI document commands (such as asyncapi validate, asyncapi convert, asyncapi bundle, etc.) or importing @asyncapi/cli in production environments caused four node-config warning messages to be printed to stderr:

WARNING: No configurations found in configuration directory: ...
WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.
WARNING: NODE_ENV value of 'production' did not match any deployment config file names.
WARNING: See https://github.com/node-config/node-config/wiki/Strict-Mode

Additionally, concurrent invocations (e.g. in parallel CI workflows or multi-process containers) could encounter an unhandled EEXIST race condition due to synchronous directory creation at module load time.

Root Cause

In src/utils/logger.ts, node-config, fs, and path were unconditionally imported and evaluated at module load time to compute and create logDir. However:

  1. winston only configures a Console transport; no file-based logging transport is used in the logger utility.
  2. The CLI configuration is managed by @oclif and custom context configs, not node-config (which is only utilized by src/apps/api).
  3. Calling fs.mkdirSync(logDir) unconditionally when logger.ts is imported creates an unneeded logs directory and causes filesystem race condition crashes when multiple CLI instances launch concurrently.

Changes Proposed

  • Removed unused config, fs, and path imports and the directory creation logic from src/utils/logger.ts.
  • Retained the existing winston console logger and stream interface intact.
  • Added comprehensive unit tests in test/unit/utils/logger.test.ts to verify logger initialization, stream message forwarding, absence of filesystem directory creation, and clean stderr output in production mode without NODE_CONFIG_DIR.

Testing

  • npm run lint: Passed with 0 errors and 0 warnings.
  • npm run build: Compiled successfully without stderr warnings.
  • npm run test:one -- test/unit/utils/logger.test.ts: 4/4 passing (100% statement, branch, func, and line coverage on src/utils/logger.ts).
  • npm run unit:test: 234 passing.

Fixes #2323
Fixes #2293

Removes unused config import and unnecessary filesystem directory creation in src/utils/logger.ts. This eliminates spurious node-config warning messages printed on stderr across CLI commands when running in production environments, and avoids race condition crashes caused by concurrent directory creation.

Fixes asyncapi#2323
Fixes asyncapi#2293

@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.

@Azizzzss Azizzzss left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up #2323 so quickly. The change to src/utils/logger.ts matches what I found: nothing ever writes to that folder, so removing the block is the right fix, and it also removes the mkdirSync race from #2293 (note that #2294 patches the same lines, so maintainers may want to decide which one to keep).

Two small notes on test/unit/utils/logger.test.ts, which I ran on Windows 11 with Node 24:

  1. should not emit node-config warnings on stderr spawns require('./lib/utils/logger'), so it needs a prior npm run build. With npm run unit:test alone (no lib/), it fails with Cannot find module './lib/utils/logger'. CI is fine because npm test runs the build first, but the DEVELOPMENT.md flow (npm run unit:test, npm run test:one) will fail for anyone who has not built. One option is to spawn with -r ts-node/register and require ./src/utils/logger.ts instead, so the test does not depend on the build output.

  2. should not create an unused logs directory at module path checks that lib/utils/logs does not exist. On a machine that ran the old code before, that folder is still there until the next rimraf lib, so the test fails locally even though the new code is correct. Removing the folder in a before() hook, or checking the source folder only, would make it stable.

Everything else looks good to me.

…est environment

- Spawn child process with -r ts-node/register to test src/utils/logger.ts directly without requiring a prior npm run build.
- Clean up any pre-existing logs folders in a beforeEach hook to ensure test stability across local runs.
@changeset-bot

changeset-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 91be086

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

@joshi-07

Copy link
Copy Markdown
Author

Thanks for the detailed review and feedback @Azizzzss!

I've addressed both points in the latest commit:

  1. Direct source testing: The child process now spawns with -r ts-node/register\ requiring ./src/utils/logger.ts\ directly, so the test suite runs seamlessly without depending on prior \lib/\ build output.
  2. Environment isolation: Added cleanup for both source and lib \logs\ paths in a \�eforeEach()\ hook to ensure pre-existing directories from earlier runs don't cause false failures.

@sonarqubecloud

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.

[BUG] Every document command prints four node-config WARNING lines before its output [BUG] asyncapi cli race condition crash

3 participants