Survive a missing xdg-open during login - #3
Merged
Conversation
On a server with no desktop, spawn("xdg-open") reports ENOENT as an
asynchronous "error" event rather than throwing, so the try/catch in
openBrowser caught nothing and the unhandled event ended `myna login x`
a moment after it had printed the paste-the-code prompt. Attach an error
handler; the caller prints the link anyway, which is all the user needs.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HWRBUb6VUCM2xBmRk91FzG
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HWRBUb6VUCM2xBmRk91FzG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
`myna login x` (and every other OAuth 2.0 login) died on a headless server right after printing the authorize link and the "Paste the code you were shown" prompt. The trace ended in the runtime's `child_process` spawn.
`openBrowser` spawns `xdg-open` to raise a browser. When the binary is missing, `spawn` does not throw; it emits an asynchronous `error` event (ENOENT). Nothing listened for it, so the unhandled event took the process down on the next tick, after the prompt was already on screen. The `try/catch` around the spawn only ever covered a synchronous throw.
Fix
Attach an `error` handler to the child. The caller prints the link as well, so a failed opener costs nothing; the user pastes the code as before.
Test
`packages/core/test/open-browser.test.ts` empties `PATH`, calls `openBrowser`, and asserts no uncaught exception surfaces. It fails on `main` with the same ENOENT trace seen in the terminal and passes with the handler.
`bun test`: 132 pass, 0 fail. `bun run typecheck`: clean.
Where it bit
Adding a second X account over SSH on the dev box. The link printed, the process died, the pasted code was orphaned (its PKCE verifier died with the process), and `myna accounts` never showed the new handle.
🤖 Generated with Claude Code
https://claude.ai/code/session_01HWRBUb6VUCM2xBmRk91FzG