Skip to content

Commit 244067d

Browse files
rap1dsMikko Koski
andauthored
GitHub Issue #213 - Exit gracefully using process.exitCode (#214)
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

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [Unreleased]
6+
7+
### Fixed
8+
9+
- [Issue #213] - fix bug with large file output cut short when using standard-clj with stdin/stdout ([PR-214])
10+
511
## [0.27.0] - 2026-03-09
612

713
### Added
@@ -287,6 +293,7 @@ All notable changes to this project will be documented in this file.
287293
[Issue #203]:https://github.com/oakmac/standard-clojure-style-js/issues/203
288294
[Issue #205]:https://github.com/oakmac/standard-clojure-style-js/issues/205
289295
[Issue #208]:https://github.com/oakmac/standard-clojure-style-js/issues/208
296+
[Issue #213]:https://github.com/oakmac/standard-clojure-style-js/issues/213
290297

291298
[commit #db857ff4]:https://github.com/oakmac/standard-clojure-style-js/commit/db857ff413f0a8625c0cd0c975684244d875705e
292299

@@ -342,3 +349,4 @@ All notable changes to this project will be documented in this file.
342349
[PR-204]:https://github.com/oakmac/standard-clojure-style-js/pull/204
343350
[PR-206]:https://github.com/oakmac/standard-clojure-style-js/pull/206
344351
[PR-209]:https://github.com/oakmac/standard-clojure-style-js/pull/209
352+
[PR-214]:https://github.com/oakmac/standard-clojure-style-js/pull/214

cli.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ function exitHappy (s) {
8888
if (cliUtil.isString(s)) {
8989
printToStdout(s)
9090
}
91-
process.exit(0)
91+
process.exitCode = 0;
9292
}
9393

9494
function exitSad (s) {
9595
if (cliUtil.isString(s)) {
9696
printToStderr(s)
9797
}
98-
process.exit(1)
98+
process.exitCode = 1;
9999
}
100100

101101
function formatDuration (durationMs) {

0 commit comments

Comments
 (0)