Repository navigation
Fix argv handling for standalone binaries - remove extra executable name (#22157) - #22169
Merged
Merged
Conversation
Collaborator
Author
|
Updated 1:33 AM PT - Aug 27th, 2025
❌ @autofix-ci[bot], your commit 477b14d has 4 failures in
🧪 To try this PR locally: bunx bun-pr 22169That installs a local version of the PR into your bun-22169 --bun |
## Summary
Fixes issue where compiled standalone binaries incorrectly included the
executable name in `process.argv`, breaking code using `parseArgs()`.
## Problem
When running `./my-app`, `process.argv` incorrectly contained:
```
["bun", "/$bunfs/root/my-app", "./my-app"] // extra executable name
```
This caused `parseArgs({ args: process.argv.slice(2) })` to throw
"Unexpected argument" errors.
## Solution
Fixed offset calculation in `cli.zig` to safely skip executable name:
```zig
// Before: offset_for_passthrough = if (bun.argv.len > 1) 1 else 0;
// After: offset_for_passthrough = @min(1, bun.argv.len);
```
This handles all edge cases safely:
- `argv.len >= 1`: Skip executable name, pass user args
- `argv.len == 0`: Return empty slice (no crash)
## Test plan
- Added regression test covering basic case and user arguments
- Verified exec-argv functionality still works correctly
- Tested edge case with empty argv (no integer overflow)
Fixes #22157
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
robobun
force-pushed
the
claude/fix-argv-issue-22157
branch
from
August 27, 2025 03:48
275285c to
48bb211
Compare
Windows uses B:/~BUN/root/ instead of //root/ for standalone binaries. Updated test to match both path formats with regex.
robobun
force-pushed
the
claude/fix-argv-issue-22157
branch
from
August 27, 2025 07:23
631bd8b to
77dfb5f
Compare
robobun
added a commit
that referenced
this pull request
Aug 28, 2025
…ame (#22157) (#22169) ## Summary Fixes an issue where compiled standalone binaries included an extra executable name argument in `process.argv`, breaking code that uses `node:util.parseArgs()` with `process.argv.slice(2)`. ## Problem When running a compiled binary, `process.argv` incorrectly included the executable name as a third argument: ```bash ./my-app # process.argv = ["bun", "/$bunfs/root/my-app", "./my-app"] # BUG ``` This caused `parseArgs()` to fail with "Unexpected argument" errors, breaking previously valid code. ## Solution Fixed the `offset_for_passthrough` calculation in `cli.zig` to always skip the executable name for standalone binaries, ensuring `process.argv` only contains the runtime name and script path: ```bash ./my-app # process.argv = ["bun", "/$bunfs/root/my-app"] # FIXED ``` ## Test plan - [x] Added regression test in `test/regression/issue/22157.test.ts` - [x] Verified existing exec-argv functionality still works correctly - [x] Manual testing confirms the fix resolves the parseArgs issue Fixes #22157 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude Bot <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Michael H <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This was referenced Sep 7, 2025
|
Thank you for the quick fix @Jarred-Sumner . You really rock our world, thanks!! |
6 of 7 tasks
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.
Summary
Fixes an issue where compiled standalone binaries included an extra executable name argument in
process.argv, breaking code that usesnode:util.parseArgs()withprocess.argv.slice(2).Problem
When running a compiled binary,
process.argvincorrectly included the executable name as a third argument:./my-app # process.argv = ["bun", "/$bunfs/root/my-app", "./my-app"] # BUGThis caused
parseArgs()to fail with "Unexpected argument" errors, breaking previously valid code.Solution
Fixed the
offset_for_passthroughcalculation incli.zigto always skip the executable name for standalone binaries, ensuringprocess.argvonly contains the runtime name and script path:./my-app # process.argv = ["bun", "/$bunfs/root/my-app"] # FIXEDTest plan
test/regression/issue/22157.test.tsFixes #22157
🤖 Generated with Claude Code