oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73k stars 2.66k forks source link

Bun shell exits process with exit code 0 #9927

Open JUSTIVE opened 5 months ago

JUSTIVE commented 5 months ago

What version of Bun is running?

1.1.0

What platform is your computer?

Darwin 23.0.0 arm64 arm

What steps can reproduce the bug?

run following code with dependencies

const runner = async (endpoint: string) => {
  await $`npx get-graphql-schema ${endpoint} | grep -v "@connection" > ./src/schema.graphql`;
  console.log('a')
  try {
    await $`pnpm relay`;
  } catch (error) {
    console.error('[getSchema] relay compilation failed', error);
    process.exit(1);
  }
};

What is the expected behavior?

graphql introspection should be done if endpoint is valid graphql endpoint, print 'a' to console output, then relay compile should run.

What do you see instead?

graphql introspection works fine, but the process exit right after it. not even 'a' printed out.

Additional information

the process's exit code is 0

Jarred-Sumner commented 5 months ago

can you provide an easier to reproduce code snippet? as-is, this code won't run

JUSTIVE commented 5 months ago

sorry for the incomplete information. I found the exact same graphql endpoint which generates the same status what I've got.

endpoint = https://graphql.anilist.co/graphql

JUSTIVE commented 5 months ago

the issue also can be reproduced on 1.1.1.

ashtonsix commented 4 months ago

I've encountered a variation of this with the .quiet() modifier, where this code never prints 'DEBUG' due to an immediate exit:

try {
  await Bun.$`cd ${path} && bun link`.quiet();
  console.log('DEBUG')
} catch (e) {
  console.log('DEBUG')
}

Get the same bad behaviour if I use the --silent flag as in Bun.$`cd ${path} && bun link --silent`. Works fine if neither the .quiet() modifier or --silent flag are present. Switched back to using promisified exec as it's more reliable.

jimlloyd commented 4 months ago

I too am hitting this bug. This works fine:

    const { stdout, stderr, exitCode } = await $`git ls-files ${dirPath}`.nothrow();

But if I add the .quiet() the process exits:

    dlog('getExistingGitFiles: dirPath:', dirPath);
    const { stdout, stderr, exitCode } = await $`git ls-files ${dirPath}`.nothrow().quiet();
    dlog({exitCode, stderr});

I see the first log message but not the second.

harshjv commented 3 months ago

This issue can also be reproduced on v1.1.10

kemicofa commented 3 months ago

I'm getting the same issue on 1.1.12.

I'm attempting to simply list some directories and it just exits silently without any additional information. Any code following the shell command does not get excuted.

await $`ls`.text();
console.log('hello world'); // <- never arrive here
0xroko commented 2 months ago

Also getting this (1.1.15), only happens if shell call is inside a function:

import { $ } from "bun";

const main = async () =>
  try {
    console.log("Deleting");
    await $`rm -f db.sqlite`;
    console.log("After");
  } catch (error) {
    console.error(error);
  }
};

main();

2024-06-22_14-53

This works:

import { $ } from "bun";

console.log("Deleting");
await $`rm -f db.sqlite`;
console.log("After");
MarvNC commented 1 month ago

I'm getting the same error on 1.1.17. After running

export async function downloadDumps(lang: LanguageCode, date: string) {
(previous code ...)
    await $`bzip2 -dc ${archivePath} >${filePath}`;
  }

  console.log(`Finished downloading and extracting ${lang} dump`);

  return filePath;
}

it exits silently without continuing.

mattvgm commented 3 weeks ago

Having a similar problem with 1.1.22

With .quiet() the shell exits without response if inside an async function

Is it the expected behaviour @Jarred-Sumner ? Thanks

index.ts - WORKS

import { $ } from "bun";

const output = await $`grep -rl "function" .`.quiet();
console.log(output);

index.ts - DOES NOT WORK

import { $ } from "bun";

(async () => {
  const output = await $`grep -rl "function" .`.quiet();
  console.log(output);
})();
Jarred-Sumner commented 2 hours ago

@0xroko @mattvgm the issue you're running into is https://github.com/oven-sh/bun/issues/13713 and is being tracked there