Skip to content

fix(login): continue when browser launch fails - #1111

Open
atyrode wants to merge 3 commits into
CleverCloud:masterfrom
atyrode:fix/login-browser-launch-fallback
Open

fix(login): continue when browser launch fails#1111
atyrode wants to merge 3 commits into
CleverCloud:masterfrom
atyrode:fix/login-browser-launch-fallback

Conversation

@atyrode

@atyrode atyrode commented Jul 14, 2026

Copy link
Copy Markdown

Refs #939

Context

clever login opens the Console login URL and then polls the OAuth endpoint. With open@10.2.0 and { wait: false }, open() returns a detached ChildProcess without installing an error listener.

On a packaged headless Linux/Nix installation without xdg-open:

$ nix shell nixpkgs#clever-tools --command clever login
Opening https://console.clever-cloud.com/cli-oauth?cli_version=4.11.0&cli_token=<redacted> in your browser to log you in…
node:events:497
      throw er; // Unhandled 'error' event
      ^

Error: spawn xdg-open ENOENT

In bundled Linux builds, if the system xdg-open is missing, the child emits an asynchronous ENOENT event. That event was unhandled, so Node terminated the CLI before OAuth polling could continue. Catching only the awaited open() call does not handle the later child-process event.

Solution

Handle both browser-launch failure paths at the existing login call site:

  • catch synchronous throws and rejected opener promises;
  • attach a one-time error listener to the returned child process;
  • print a static warning asking the user to open the already-displayed URL manually;
  • continue the existing OAuth polling flow.

The change remains local to login and preserves { wait: false }. It does not change polling, cancellation, authentication, timeouts, the shared browser helper, launcher exit-code handling, or process lifetime. The launch error is intentionally not logged because its spawn arguments can contain the credential-bearing login URL.

How to test

  • npm run validate
  • build the Rollup bundle and Linux pkg binary;
  • run the packaged binary without xdg-open against loopback-only API and Console endpoints;
  • verify the process remains alive and continues polling after the launcher error;
  • verify a genuine polling failure still exits with code 1;
  • verify Ctrl+C still terminates promptly.

The packaged Linux reproduction passes. The original Windows report remains unverified; please add the build:win label so the reporter can test a Windows preview.

Optional regression coverage

Three dependency-free helper tests are available separately if maintainers want to adopt a test entry point. They are intentionally not part of this source-only PR:

@atyrode
atyrode requested a review from a team as a code owner July 14, 2026 00:27

@hsablonniere hsablonniere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @atyrode, solid fix. I went and checked how a few other CLIs handle this case (gh, gcloud) and left some suggestions inline.

Comment thread src/commands/login/login.command.js Outdated
Comment thread src/commands/login/login.command.js
atyrode and others added 2 commits July 15, 2026 20:13
Co-authored-by: Hubert SABLONNIÈRE <hubert.sablonniere@gmail.com>
@atyrode

atyrode commented Jul 15, 2026

Copy link
Copy Markdown
Author

Thanks! I applied both suggestions. GitHub’s batch application introduced mixed line endings in the changed block, so I added a formatting-only commit to normalize them. npm run validate passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants