zaaack / foy

A simple, light-weight, type-friendly and modern task runner for general purpose.
http://zaaack.github.io/foy
MIT License
260 stars 14 forks source link

Foy's exit code is always "0" #23

Open fromkeith opened 2 hours ago

fromkeith commented 2 hours ago

When a task fails, Foy stops, and exits with an exit code of "0". I would expect it to exit with a non-zero exit code. This makes it impossible to abort an automated build.

Test Case

Foyfile.js

const { task, desc, option, fs, logger } = require('foy');
task('test', async (ctx) => {
    const result = await ctx.exec('exit 1');
    console.log(`result: ${result.exitCode}`);
});

Command + Output:

> foy-test$ npx foy test
[info] $ exit 1
[error] Error: Command failed with ENOENT: exit 1
spawn exit ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn exit',
  path: 'exit',
  spawnargs: [ '1' ],
  originalMessage: 'spawn exit ENOENT',
  shortMessage: 'Command failed with ENOENT: exit 1\nspawn exit ENOENT',
  command: 'exit 1',
  exitCode: undefined,
  signal: undefined,
  signalDescription: undefined,
  stdout: undefined,
  stderr: undefined,
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
✖ test [duration: 0.08s]
> foy-test$ echo $?
0

I would have expected echo $? to print 1, indicating the task failed. And thus stopping execution.

fromkeith commented 2 hours ago

Another example quickly... I would expect npx foy test && echo "Hello" to not print Hello, but since foy returns 0, it is printed.