Commit 244067d
From Node.js docs:
> Calling process.exit() will force the process to exit as quickly as possible even if there are still asynchronous operations pending that have not yet completed fully, including I/O operations to process.stdout and process.stderr.
https://nodejs.org/docs/latest-v26.x/api/process.html#processexitcode
The issue can be reproduced when formatting a large file and using
standard-clj in stdin/out mode and piping the result to another process.
Steps to reproduce:
```
bb -e '(spit "large-test.clj" (str/join "\n" (map #(str "(defn func-" % " [x] (+ x " % "))") (range 10000))))'
cat large-test.clj | node cli.mjs fix - | cat > large-test-output.clj
wc -l large-test.clj large-test-output.clj
9999 large-test.clj
2117 large-test-output.clj
12116 total
```
Expected: Line count after formatting should be close to the original
line count
Actual: The file is cut short. The line count of the formatted file is
significantly less.
Please note that `| cat > ` is essential. This issue doesn't happen when
stdout is redirected directly to a file, i.e.
It's worth noting that this change changes the semantics of exitHappy
and exitSad function. The don't anymore exit immediately, but instead
just set the exit code for the process. The exitHappy and exitSad
function will return to the caller and if there's any code after calling
exitHappy/Sad, that code will be executed. I checked the code and it
seems to be that exitHappy/Sad calls are always the last piece of code
and there's nothing after them, so this should be a safe change.
Co-authored-by: Mikko Koski <mikkokos@gmail.com>
1 parent 9f51c9e commit 244067d
2 files changed
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
5 | 11 | | |
6 | 12 | | |
7 | 13 | | |
| |||
287 | 293 | | |
288 | 294 | | |
289 | 295 | | |
| 296 | + | |
290 | 297 | | |
291 | 298 | | |
292 | 299 | | |
| |||
342 | 349 | | |
343 | 350 | | |
344 | 351 | | |
| 352 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| |||
0 commit comments