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

Bun fails ~sometimes~ running shell command "patch" #15316

Open
jpasquers opened this issue Nov 21, 2024 · 0 comments
Open

Bun fails ~sometimes~ running shell command "patch" #15316

jpasquers opened this issue Nov 21, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@jpasquers
Copy link

jpasquers commented Nov 21, 2024

What version of Bun is running?

1.1.36

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Setup Steps

  1. Make sure gpatch is installed (brew install gpatch) - version 2.7.6. (Can check patch --version to confirm)
  2. Within a fresh directory
  3. Run bun init
  4. Populate index.ts with this:
import {$} from "bun";

try {
    await $`patch '-p1' --no-backup-if-mismatch -d '.' < './fix.patch'`;
    console.log("Succeeded :)");
}
catch(e) {
    console.log("Failed :(");
}
  1. Create fix.patch and put this in it:
--- a/stuff.txt
+++ b/stuff.txt
@@ -1,7 +1,7 @@
 Hello
 there
 general
-Kenobi
+Homie
 how
 art
 thou
  1. Create stuff.txt and put this in it
Hello
there
general
Kenobi
how
art
thou

Control Scenario - Bun patch works, and direct patch works

  1. Run patch -p1' --no-backup-if-mismatch -d '.' < './fix.patch. This is the normal gpatch behavior
  2. As a result you should see a success message and stuff.txt should have “Homie” instead of “Kenobi”, meaning the patch worked
  3. undo the patch in stuff.txt so it says Kenobi again.
  4. Run bun run index.ts
  5. You should see another success and stuff.txt is again changed to “Homie”.
  6. Undo the patch again

Problem scenario - direct patch works, Bun command fails.

  1. Make sure stuff.txt is in the original state, with Kenobi
  2. Create an inner folder (I called mine src) and move stuff.txt into that folder.
  3. Change fix.patch to point to the correct paths, aka:
--- a/src/stuff.txt
+++ b/src/stuff.txt
@@ -1,7 +1,7 @@
 Hello
 there
 general
-Kenobi
+Homie
 how
 art
 thou
  1. From the original directory (aka not src), run the patch command again, i.e.: patch -p1' --no-backup-if-mismatch -d '.' < './fix.patch
  2. Confirm that this succeeded and still changed the values in stuff.txt from Kenobi to Homie, and then reset it back to Kenobi
  3. Run bun run index.ts again. You should see a failure with: /opt/homebrew/bin/patch: **** out of memory

What is the expected behavior?

Bun execution of gpatch should succeed in both cases, not produce an out of memory error.

What do you see instead?

/opt/homebrew/bin/patch: **** out of memory

Additional information

I understand this is a niche interaction of a particular shell command executed within Bun. But given the exact same scenario works with the direct command, I feel this could be a problem within Bun. I also wonder if the same bug causing this could be breaking other command executions

@jpasquers jpasquers added bug Something isn't working needs triage labels Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant