Skip to content

[DOCS] Setting an invalid loglevel does not terminate the execution of the change. #8082

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

Closed
2 tasks done
69cali69 opened this issue Feb 4, 2025 · 3 comments
Closed
2 tasks done
Labels
Bug thing that needs fixing Documentation documentation related issue

Comments

@69cali69
Copy link

69cali69 commented Feb 4, 2025

Is there an existing issue for this?

  • I have searched the existing issues

This is a CLI Docs Enhancement, not another kind of Docs Enhancement.

  • This is a CLI Docs Enhancement.

Description of Problem

When updating the loglevel of the npm global configuration, passing an invalid log level argument will not terminate the execution of the command itself. It will update the configuration with the invalid argument. This literally turns off any logs from the package manager. Node commands will work, but even checking the NPM version with "npm -v" will cease to work. Reinstalling will not fix this issue unless you explicitly delete the .npmrc file or edit it.

Potential Solution

The documentation of this potential issue should be mentioned with the steps to fix it or an error should be thrown when an incorrect log level is passed and when a subsequent NPM command executed.

Docs URL

https://docs.npmjs.com/cli/v8/using-npm/logging

@69cali69 69cali69 added Documentation documentation related issue Needs Triage needs review for next steps labels Feb 4, 2025
@milaninfy
Copy link
Contributor

milaninfy commented Feb 4, 2025

One of the easy solution to this would be to reset log level at the command level.
as mentioned in documentation that you can pass logging config while running a command.
e.g.
debugging invalid logging config with -ddd or other logging flags like --verbose etc from documentation. as you can see from below logs it says that it encountered invalid config and what are the accepted values for that config

~/workarea/rep $ cat .npmrc
loglevel=some-random-value
~/workarea/rep $ npm ls                 
~/workarea/rep $ npm ls -ddd
npm verbose cli /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/node /Users/milaninfy/.nvm/versions/node/v22.9.0/bin/npm
npm info using [email protected]
npm info using [email protected]
npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/lib/node_modules/npm/npmrc
npm silly config load:file:/Users/milaninfy/workarea/rep/.npmrc
npm silly config load:file:/Users/milaninfy/.npmrc
npm silly config load:file:/Users/milaninfy/.nvm/versions/node/v22.9.0/etc/npmrc
npm verbose title npm ls
npm verbose argv "ls" "--loglevel" "silly"
npm verbose logfile logs-max:10 dir:/Users/milaninfy/.npm/_logs/2025-02-04T17_42_28_612Z-
npm verbose logfile /Users/milaninfy/.npm/_logs/2025-02-04T17_42_28_612Z-debug-0.log
npm warn invalid config loglevel="some-random-value" set in /Users/milaninfy/workarea/rep/.npmrc
npm warn invalid config Must be one of: silent, error, warn, notice, http, info, verbose, silly
npm silly logfile start cleaning logs, removing 2 files
npm silly packumentCache heap:4345298944 maxSize:1086324736 maxEntrySize:543162368
npm silly logfile done cleaning log files
[email protected] /Users/milaninfy/workarea/rep
└── (empty)

npm verbose cwd /Users/milaninfy/workarea/rep
npm verbose os Darwin 24.3.0
npm verbose node v22.9.0
npm verbose npm  v11.0.0
npm verbose exit 0
npm info ok

@vijit1018
Copy link

This CLI Docs Enhancement request highlights a critical issue with npm's global configuration when an invalid log level argument is passed. The current behavior allows the invalid log level to be set without error, which effectively disables all npm logs, making even basic commands like npm -v unresponsive. The issue persists until the .npmrc file is manually deleted or edited.

Proposed Fix

  1. Documentation Update
  • The npm CLI documentation should clearly warn users about this potential issue.
  • It should provide steps to manually fix the issue (i.e., delete or edit .npmrc).
  1. Error Handling Improvement

The CLI should validate the log-level argument and reject invalid values instead of silently applying them.
When an invalid log level is detected, an error message should be thrown, preventing the misconfiguration.

@milaninfy milaninfy added Bug thing that needs fixing and removed Needs Triage needs review for next steps labels Feb 25, 2025
@wraithgar
Copy link
Member

The CLI should validate the log-level argument and reject invalid values instead of silently applying them.
When an invalid log level is detected, an error message should be thrown, preventing the misconfiguration.

These are already planned for the next semver major version of npm. As of now all we can do is warn, since rejecting them is a breaking change. Those warnings were added in npm 11.2.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Documentation documentation related issue
Projects
None yet
Development

No branches or pull requests

4 participants