Skip to content

bug: rtk prettier silently hides prettier 3 failures (stdout-only capture + [warn] filter) #2878

Open
KCuppens/rtk
#1

Description

@linustalacko

Summary

rtk prettier --check on a project with real formatting failures (prettier exits 1) reports either a false All files formatted correctly or an uninformative bare Checking formatting... — never the actual list of files that need formatting. Confirmed on rtk 0.43.0 (Homebrew, macOS arm64), reproduced both from a clean source clone and against the installed binary.

Not a duplicate of #2395 (that one is the binary-not-installed case). Also appears not to be fixed by whatever closed #221 — see "Relationship to #221 and #2395" below.

Root cause (verified against the v0.43.0 tag, commit 5a7880d)

Two independent defects compound:

  1. src/cmds/js/prettier_cmd.rs:24 — run() calls runner::run_filtered(..., RunOptions::stdout_only()). Prettier 3.x writes Checking formatting... to stdout but writes the per-file [warn] <file> lines and the final Code style issues found in N files... summary to stderr. With stdout_only(), filter_prettier_output never even sees those lines — they're discarded before filtering runs.

  2. src/cmds/js/prettier_cmd.rs:52 — even if stderr were captured, filter_prettier_output explicitly excludes any line .contains("[warn]"). Prettier 3 emits failing files as exactly [warn] <file> (Prettier 2 used bare filenames — the format the function's parsing logic and its test fixtures, lines 128-184, still assume). This is the original defect described in bug: rtk prettier --check incorrectly reports "All files formatted correctly" when files need formatting #221's issue body.

A third factor decides which wrong message you see: src/core/guard.rs:6-12, guard::never_worse(). It's a pure token-count comparator with no correctness awareness — it keeps whichever of {filtered, raw} has fewer estimated tokens. Because filter_stdout_only also makes raw_for_tracking stdout-only, and filter_prettier_output("Checking formatting...\n") (no file lines ever reach it) produces the longer string "Prettier: All files formatted correctly", the guard discards it for being longer and falls back to raw stdout — which is just "Checking formatting...". That's why the exact wrong message differs by build even though the underlying defect (silently dropping the failing-file list) is the same one.

Repro (verified live against the installed rtk 0.43.0 binary)

$ cat package.json
{"devDependencies": {"prettier": "^3.3.0"}}
$ printf 'const x = {\n    a:1,\n  b:2\n}\n' > messy.js

$ pnpm exec prettier --check . 2>/dev/null   # stdout only
Checking formatting...
$ pnpm exec prettier --check . 1>/dev/null   # stderr only
[warn] messy.js
[warn] pnpm-lock.yaml
[warn] Code style issues found in 2 files. Run Prettier with --write to fix.
$ pnpm exec prettier --check .; echo "exit=$?"
exit=1

$ rtk prettier --check .; echo "exit=$?"
Checking formatting...

exit=1

rtk prettier's exit code correctly propagates (1), but the printed message gives no indication anything failed or which files are affected. An agent piping through head/tail, or reading only stdout, sees a clean-looking Checking formatting... with no files-need-formatting message anywhere.

Relationship to #221 and #2395

Environment

  • rtk 0.43.0, Homebrew install, macOS arm64 (0.40.0 also reported affected; only 0.43.0 was independently re-verified for this report)
  • Node v22.23.1, pnpm 10.22.0, prettier 3.9.4

Suggested fix

  • Capture stderr too (drop stdout_only(), or add a stderr-aware variant) so filter_prettier_output actually sees prettier 3's real output.
  • Replace the [warn]/[error] line exclusion at line 52 with logic that recognizes [warn] <file> as a failing-file line rather than noise — Prettier 2's bare-filename format can likely be kept alongside it.
  • Add .svelte to the tracked extension list (lines 54-61) while in the area — currently absent.
  • The test module (lines 128-184) encodes Prettier 2's output shape; add Prettier-3-shaped fixtures ([warn] <file> arriving via stderr) so a regression here fails CI.

Local workaround

We route around this with a hook-level exclusion in config.toml (mirrors the rewrite rule in src/discover/rules.rs, not a general fix — just stops rtk intercepting prettier at all so real output reaches the caller unfiltered):

[hooks]
exclude_commands = [
    '^((p?np(m|x)|p?npm\s+(exec|run|run-script)|npm\s+(rum|urn|x)|pnpm\s+dlx)\s+)?prettier(\s|$)',
]

Activity

  1. linustalacko commented on Jul 8, 2026

    @linustalacko
    Author

    Companion issue: #2879 (same class of bug — rtk output-filtering silently hides real failures — found and verified together; unrelated code path so filed separately).

  2. pszymkowiak commented on Jul 8, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 93%

    Summary

    rtk prettier discards prettier 3's stderr-only failure output (stdout_only capture) and also filters out [warn]-prefixed failing-file lines, silently hiding real formatting failures despite correct exit code; fix in prettier_cmd.rs (capture stderr, fix [warn] filter) with a guard.rs interaction to be aware of.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/cmds/js/prettier_cmd.rs
    • src/core/guard.rs

    Triaged automatically by wshm · This is an automated analysis, not a human review.

  3. added a commit that references this issue on Jul 8, 2026
    05e8cef
  4. KuSh commented on Sep 12, 2026

    @KuSh
    Collaborator

    Heads-up: once #3772 merges, this issue's manifestation changes. Today rtk prettier --check silently swallows the [warn] lines (you get a false "all good" or a bare "Checking formatting..."). After #3772, stderr is forwarded raw and unfiltered instead, so on a large repo with many unformatted files you'll get the full unfiltered prettier report — observed ~26k tokens on a large repo, versus near-zero today. Worth bumping priority on the second half of this issue (extending filter_prettier_output, or a stderr-aware equivalent, to summarize the [warn] lines) now that the failure mode is "noisy" rather than "silent."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibugpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions