Skip to content

tsc wrapper: --pretty flag suppresses errors and prints fake "compilation completed" success message #1772

Closed

Description

@MbBrainz

Summary

When rtk tsc runs with the --pretty flag, type errors are silently swallowed and RTK reports TypeScript: No errors found even though tsc exits with a non-zero status. Without --pretty, RTK parses errors correctly. The bug is reliably reproducible.

Affected version

rtk 0.39.0 (latest at time of filing, installed via Homebrew on macOS arm64).

Reproduction

/tmp/rtk-test.ts:

const x: number = "string";

/tmp/tsconfig-rtk-test.json:

{
  "compilerOptions": {
    "strict": true,
    "noEmit": true,
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node"
  },
  "files": ["/tmp/rtk-test.ts"]
}

Run both:

$ rtk tsc --noEmit -p /tmp/tsconfig-rtk-test.json
../../../../tmp/rtk-test.ts(1,7): error TS2322: Type 'string' is not assignable to type 'number'.
═══════════════════════════════════════
TypeScript: 1 errors in 1 files
# exit code: 2

$ rtk tsc --noEmit --pretty -p /tmp/tsconfig-rtk-test.json
TypeScript: No errors found
# exit code: 2

Expected vs actual

  • Expected: With --pretty, RTK should still display the errors (or at least not lie) — minimum bar is that the textual summary matches reality when tsc exits non-zero.
  • Actual: Exit code is correctly propagated (2), but stdout reports No errors found. A consumer looking at output (human or LLM) sees a fake success message.

This is dangerous in CI/agent contexts: errors get hidden by a wrapper that claims success, and downstream steps (e.g. && next build) may proceed as if green. Concretely, this was discovered while running npx tsc --noEmit --pretty from a Claude Code session — the wrapper hid type errors that Vercel's build then caught, causing a failed deploy.

Root cause hypothesis

tsc --pretty emits ANSI escape codes (colors, formatting) on each error line. RTK's regex for matching tsc error lines (path(L,C): error TSxxxx: ...) does not account for embedded ANSI sequences, so it counts zero matches. With zero parsed errors, RTK synthesizes No errors found regardless of the actual exit code.

Suggested fix

Either (or both):

  1. Strip ANSI escape sequences from each line before regex-matching error lines.
  2. Cross-check parsed error count against the child exit code: if exit != 0 && parsed_errors == 0, fall back to passthrough of the raw output rather than synthesizing a success summary. This is a good general invariant — RTK's summary should never contradict the wrapped tool's exit code.

Option 2 is the safer default since it also catches future tsc output format changes that the regex hasn't adapted to.

Activity

  1. added
    bug
    help wanted
    on May 27, 2026
  2. pszymkowiak commented on May 27, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 97%

    Summary

    RTK's tsc wrapper fails to parse ANSI-colored output from --pretty flag, synthesizing a false 'No errors found' summary while correctly propagating a non-zero exit code — dangerous in CI/agent pipelines.

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

    📁 Relevant files
    • src/wrappers/tsc.rs

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

  3. SQReder commented on Aug 16, 2026

    @SQReder

    Still reproduces on 0.45.0, and there is a trigger that needs no --pretty flag at all — which I think raises the severity of this issue.

    @typescript/native (tsgo, the TypeScript 7 native preview) emits the pretty format unconditionally, including when stdout is a pipe. Classic tsc turns pretty off automatically when it is not writing to a TTY, which is why this bug normally hides behind an explicit --pretty. tsgo does not, so in any workspace whose node_modules/.bin/tsc resolves to @typescript/native, an ordinary invocation with no flags silently reports a clean typecheck.

    Verified against @typescript/native 7.0.2 on rtk 0.45.0, one source file containing two genuine TS2322 errors:

    $ rtk tsc --noEmit -p tsconfig.json
    TypeScript: No errors found
    EXIT=1
    
    $ rtk tsc --pretty false --noEmit -p tsconfig.json
    src/probe.ts(1,14): error TS2322: Type 'string' is not assignable to type 'number'.
    src/probe.ts(2,14): error TS2322: Type 'string' is not assignable to type 'number'.
    ═══════════════════════════════════════
    TypeScript: 2 errors in 1 files
    EXIT=1
    

    Same compiler, same project, same errors; the only difference is the output format. Note that tsgo exits 1 on type errors where classic tsc exits 2, so an exit-code guard should test != 0 rather than a specific value.

    Minimal repro on stock [email protected] (rtk 0.45.0), for a version that does not need the native preview installed:

    $ rtk tsc --noEmit
    src/probe.ts(1,14): error TS2322: Type 'string' is not assignable to type 'number'.
    src/probe.ts(2,14): error TS2322: Type 'string' is not assignable to type 'number'.
    TypeScript: 2 errors in 1 files
    A_EXIT=2
    
    $ rtk tsc --pretty --noEmit
    TypeScript: No errors found
    [full output: ~/.local/share/rtk/tee/1786880202_tsc.log]
    B_EXIT=2
    

    Two things that may help whoever picks this up:

    1. The tee log written alongside the false summary contains the complete, correct error output. The data reaches rtk intact — only the summariser's regex misses it. Parsing the pretty form is a matter of stripping ANSI first and then matching ^(?<file>.+?):(?<line>\d+):(?<col>\d+) - error (?<code>TS\d+): in addition to the existing path(line,col): error TSxxxx form.

    2. Independently of the regex, the exit-code guard proposed in tsc filter: "TypeScript: No errors found" is printed on a non-zero exit, so a tsc that never ran reads as a clean typecheck #3220 would have contained this: when the wrapped command exits non-zero but zero diagnostics were parsed, print that the output could not be parsed and point at the tee log rather than a success line. The two issues have different root causes but the same blast radius, and that guard is the one that fails safe for both.

    Context for why the severity is worth a second look: rtk's whole purpose is to be the layer an agent reads instead of raw output, so a false green is the one failure mode that cannot be recovered downstream. In our case a real TS2304: Cannot find name '...' (a missing import) passed a typecheck this way and surfaced only later, as a 500 in an integration test.

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:clibughelp wantedpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions