cli icon indicating copy to clipboard operation
cli copied to clipboard

[BUG] npm doesn't log intermediate fetch retry failures

Open hashtagchris opened this issue 10 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

This issue exists in the latest npm version

  • [X] I am using the latest npm

Current Behavior

npm retries idempotent read requests to the registry (ref). But it doesn't log the intermediate errors, regardless of loglevel.

Logging every http response or network failure would aid investigations. For example, if npm install is slow, it would useful to know why initial attempts failed, and how long individual http requests took.

Expected Behavior

Every http response or network failure is logged when the loglevel is verbose or higher.

Steps To Reproduce

Intentionally using https://httpbin.org for fault injection. When the supplied package name, 503, is appended to https://httpbin.org/status, that causes our "registry" to return a 503 status code, a retryable response.

  1. npm view 503 --loglevel silly --registry=https://httpbin.org/status --fetch-retries=2 (2 retries is the default)
  2. The command will fail with error 503 SERVICE UNAVAILABLE. That's expected.
  3. Inspect the log output. You'll see there were three attempts to retrieve package details, but only the final 503 http response is recorded. Log snippet:
31 silly logfile done cleaning log files
32 http fetch GET 503 https://httpbin.org/status/503 80700ms attempt #3 (cache skip)
33 timing command:view Completed in 80705ms
34 verbose stack HttpErrorGeneral: 503 SERVICE UNAVAILABLE - GET https://httpbin.org/status/503

Environment

; "user" config from /Users/hashtagchris/.npmrc

@npm:registry = "https://npm.pkg.github.com" 
//npm.pkg.github.com/:_authToken = (protected) 
//registry-sandbox.npm.red/:_authToken = (protected) 
//registry.npmjs.org/:_authToken = (protected) 
logs-max = 1000 

; node bin location = /Users/hashtagchris/.nvm/versions/node/v20.12.2/bin/node
; node version = v20.12.2
; npm local prefix = /Users/hashtagchris/r/npm
; npm version = 10.5.2
; cwd = /Users/hashtagchris/r/npm
; HOME = /Users/hashtagchris
; Run `npm config ls -l` to show all defaults.

hashtagchris avatar Apr 12 '24 17:04 hashtagchris