Skip to content
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

[BUG] Exit handler never called when calling npm adduser #6505

Closed
2 tasks done
gabrielyotoo opened this issue May 26, 2023 · 4 comments
Closed
2 tasks done

[BUG] Exit handler never called when calling npm adduser #6505

gabrielyotoo opened this issue May 26, 2023 · 4 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@gabrielyotoo
Copy link

gabrielyotoo commented May 26, 2023

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When I run the command

npm adduser --registry my_register <<!
$USERNAME
$PASSWORD
$EMAIL
!

to log in to a registry, I receive the error

npm notice Log in on MY_REGISTER
Username: myuser
Password: npm ERR! Exit handler never called!

npm ERR! This is an error with npm itself. Please report this error at:
npm ERR!     <https://github.com/npm/cli/issues>

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2023-05-26T14_31_01_533Z-debug-0.log

Is there any other methods to log in automatically via shell script? I am unable to use expect because some users of the script run it on windows.

Expected Behavior

The expected behavior is to log in to the registry when running

npm adduser --registry my_register <<!
$USERNAME
$PASSWORD
$EMAIL
!

Steps To Reproduce

  1. In MacOS
  2. npm version 8.19.4
  3. Try to run
npm adduser --registry my_register <<!
$USERNAME
$PASSWORD
$EMAIL
!
  1. See error

Environment

  • npm: 8.19.4
  • Node.js: v16.15.1
  • OS Name: MacOS 13.2 (22D49)
  • System Model Name: MacBook Pro M1
  • npm config:
; "user" config from /Users/me/.npmrc

//my-registry/:_authToken = (protected) 

; node bin location = /Users/me/.nvm/versions/node/v16.15.1/bin/node
; node version = v16.15.1
; npm local prefix = /Users/me/projects/my_app
; npm version = 8.19.4
; cwd = /Users/me/projects/my_app
; HOME = /Users/me
; Run `npm config ls -l` to show all defaults.
@gabrielyotoo gabrielyotoo added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels May 26, 2023
@gabrielyotoo
Copy link
Author

If you need to know exactly what is the registry, please let me know.

@cco3
Copy link

cco3 commented Jun 7, 2023

The issue is with npm read. It relies on the readline module and creates a new readline interface for each input. The first time it's created, all your input is consumed. The second time, because the data is consumed, the event loop empties before the promise managing readline ever settles, and the program just exits.

A few options (non-exhaustive):

  1. Check input.readableEnded and watching for the readline close event here, but that will just give an opportunity for a cleaner exit, not actual read the data the way you expect.
  2. Use fs.read in the read module to read the input stream one character at a time, provided it supplies a file descriptor. There are probably some edge cases where this won't work.
  3. Restructure the read module to provide generate object that manages a readline interface so that calling code can hang on to it and not implicitly create several readline interfaces.

None of these options seems very satisfactory. It would be nice if readline just provided an option to guarantee that it would not read more than a line at a time. But I'm not even sure that's possible given the way the underlying streams work.

@gabrielyotoo
Copy link
Author

Thank you for your response. I'll try to achieve my goal in another ways! Thank you again!

@cco3
Copy link

cco3 commented Jun 7, 2023

Related bug here: npm/read#36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

2 participants