stdlib-js / stdlib-js/stdlib

CLI wrapper swallows subcommand exit codes

オープン
#11,293 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
Bug
主要言語
JavaScript
スター
6k
フォーク
1.3k
平均マージ
1日 3時間
マージ済み PR(30日)
611

説明

### Description

While testing the CLI wrapper (bin/cli), I noticed that it doesn’t properly return the exit status of the commands it runs.

Right now, the wrapper only listens for the error event on the spawned process, which means it only catches cases where the process fails to start (like when a command isn’t found). However, it doesn’t handle exit or close events.

Because of this, if a subcommand runs but fails (returns a non-zero exit code), the main CLI still exits with 0, indicating success.

This can be misleading and may cause issues in scripts, CI/CD pipelines, or any automation that relies on correct exit codes to detect failures.

---

### Error Details

```bash
node .\bin\cli capitalize; Write-Output "WRAPPED_EXIT:$LASTEXITCODE"
→ WRAPPED_EXIT:0

node .\node_modules\@stdlib\string\capitalize\bin\cli; Write-Output "DIRECT_EXIT:$LASTEXITCODE"
→ DIRECT_EXIT:1
```

### Related Issues

None that I could find.

### Questions

No.

### Demo

_No response_

### Reproduction

```shell
- Run a wrapped stdlib CLI subcommand with invalid input that should cause it to fail.

- Check the shell's exit code (echo $? on Linux/Mac or $LASTEXITCODE on Windows).

- Observe the discrepancy between the wrapped command and the direct module command.
```

### Expected Results

```shell
The parent CLI process should catch the child's exit status and exit with the same non-zero code.
```

### Actual Results

```shell
The parent CLI process exits with code 0.
```

### Version

develop

### Environments

Node.js

### Browser Version

N/A

### Node.js / npm Version

v22.17.1

### Platform

Windows

### Checklist

- [x] Read and understood the [Code of Conduct](https://github.com/stdlib-js/stdlib/blob/develop/CODE_OF_CONDUCT.md).
- [x] Searched for existing issues and pull requests.

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

Start by reading bin/cli and reproduce the wrapped and direct command cases from the issue, checking the parent process exit status on the available shell. Trace how the spawned subcommand currently reports errors and exits. Done means a failing subcommand causes the wrapper to return the same non-zero status while command-not-found behavior remains covered.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js
領域
cli
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
55/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。