Skip to content

fix(actions): emit trailing newline from node-stdout, unblocks read#29

Merged
jan-kubica merged 2 commits into
mainfrom
fix/node-stdout-newline
May 13, 2026
Merged

fix(actions): emit trailing newline from node-stdout, unblocks read#29
jan-kubica merged 2 commits into
mainfrom
fix/node-stdout-newline

Conversation

@jan-kubica
Copy link
Copy Markdown
Contributor

Root cause (finally)

Three consecutive dispatches of stella/stdnum's release against `v0.0.1` exited 1 with no script output. After ruling out file-mode (#28), `NODE_AUTH_TOKEN` placeholder handling (#27), and a few other hypotheses, I instrumented `publish.sh` with `set -x` on a temporary branch. The trace from that diagnostic dispatch (stdnum run 25810975562) showed the script reaching:

```

  • read -r PACKAGE_NAME PACKAGE_VERSION
    ++ node -e '...process.stdout.write(name + "\t" + version);' ${PKG_JSON_FILE}
  • rm -f ${PKG_JSON_FILE} # the EXIT trap firing
    ##[error]Process completed with exit code 1.
    ```

`rm -f` is the EXIT trap — so the script exited cleanly via trap, but with code 1.

Per `man bash`, `read` returns 0 "unless end-of-file is encountered". The node script wrote `name\tversion` with no trailing newline, so `read` hit EOF before finding a delimiter and returned 1 — even though it correctly assigned both variables. `set -e` then exited the script before reaching the subsequent `[[ -z PACKAGE_NAME ]]` check that would have emitted a meaningful error.

Fix

A 4-byte change: append `"\n"` to the node-emitted string.

```diff

  • process.stdout.write((j.name ?? "") + "\t" + (j.version ?? ""));
  • process.stdout.write((j.name ?? "") + "\t" + (j.version ?? "") + "\n");
    ```

Test plan

  • shellcheck clean
  • local repro: previously silent-exit 1; now reaches the next gate (npm version check) and emits the expected error message
  • CI green
  • post-merge: bump SHA pin in stella/stdnum's release.yml, re-dispatch against `v0.0.1`. Expected: composite reaches `already_published` early-return and exits 0 without re-publishing

The diagnostic instrumentation that surfaced this lives on a separate `debug/publish-trace` branch and will be cleaned up after this lands.

Apologies

Three failed dispatches in public. The earlier fixes (#26, #27, #28) were all real concerns, just not THIS concern. Should have instrumented earlier instead of iterating on hypotheses.

The diagnostic dispatch (stella/stdnum#run-25810975562, debug branch)
finally captured the actual failure path. The script reaches:

  read -r PACKAGE_NAME PACKAGE_VERSION < <(node -e '
    ... process.stdout.write(name + "\t" + version);
  ' "${PKG_JSON_FILE}")

and then exits 1 via the EXIT trap — meaning `read` returned non-zero
and `set -e` killed the script.

Per `man bash`, `read` "returns 0 unless end-of-file is encountered."
The node script wrote `name\tversion` with no trailing newline, so
`read` hit EOF before finding a delimiter and returned 1 — even
though it correctly assigned both variables. `set -e` then exited
the script before reaching the subsequent `[[ -z PACKAGE_NAME ]]`
check that would have emitted a meaningful error.

A four-byte fix: append "\n" to the node-emitted string. Verified
locally — script now reaches the next gate (npm version check)
instead of silent-exiting.

The diagnostic instrumentation that surfaced this is NOT included
in this commit — it lives on a separate `debug/publish-trace` branch
and will be cleaned up after this lands.
@jan-kubica jan-kubica requested a review from nnad3N as a code owner May 13, 2026 16:06
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the publish.sh script to ensure a trailing newline is included when outputting the package name and version from Node.js. This change prevents the bash read command from returning a non-zero exit code, which would otherwise terminate the script under set -e. Additionally, a ShellCheck suppression was added for template literals. The reviewer suggested using console.log with a template literal as a more idiomatic and readable alternative to process.stdout.write, providing a code suggestion to implement this improvement.

// Trailing newline is required: bash `read` returns non-zero on EOF
// without a delimiter even when the variables were assigned. Under
// `set -e` that non-zero kills the script silently right here.
process.stdout.write((j.name ?? "") + "\t" + (j.version ?? "") + "\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For writing line-based output to stdout in Node.js, it's more idiomatic and slightly more concise to use console.log(), which automatically appends a newline. You could also use a template literal to improve readability. This would also make the shellcheck disable comment on line 75 more accurate, as it mentions template literals.

Suggested change
process.stdout.write((j.name ?? "") + "\t" + (j.version ?? "") + "\n");
console.log(`${j.name ?? ""}\t${j.version ?? ""}`);

Replaces `process.stdout.write(... + "\\n")` with
`console.log(`${name}\\t${version}`)`. console.log appends the
required newline automatically, and the template literal makes the
shellcheck disable directive (which mentions template literals)
accurate. No functional change.

Verified locally — script still reaches the next gate.

Addresses gemini medium on PR #29.
@jan-kubica
Copy link
Copy Markdown
Contributor Author

CC on behalf of @jan-kubica

Applied in latest commit. `console.log` + template literal is cleaner and now the shellcheck disable directive accurately matches what's in the line. Verified locally that the script still reaches the next gate.

@jan-kubica jan-kubica merged commit 96b8912 into main May 13, 2026
1 check passed
@jan-kubica jan-kubica deleted the fix/node-stdout-newline branch May 13, 2026 16:10
@github-actions github-actions Bot locked and limited conversation to collaborators May 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant