Skip to content

fix(cli): print config-load warnings to stderr - #13416

Merged
zkochan merged 3 commits into
mainfrom
fix-13361
Jul 27, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-13361

Conversation

@zkochan

@zkochan zkochan commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #13361.

pnpm 11 prints config-load warnings to stderr (getConfig collects them while reading config and prints them with console.warn), while pacquet routed its one config-load warning — the "install settings left under package.json's pnpm field" warning from #13359 — through LogEvent::Global into the default reporter's stdout frame. A script capturing stdout got the warning mixed into the command's own output.

This PR gives pacquet a config-warning channel (cli_args::config_warnings::emit_config_warning) that writes a [WARN]-labelled line straight to stderr, outside the reporter, and emits the ignored-field warning through it:

  • The channel prints unconditionally — on every reporter, matching console.warn in the TypeScript CLI's getConfig.
  • Color styling is keyed off stdout's TTY-ness (not stderr's), matching formatWarn's use of chalk's default, stdout-probing instance.
  • Future config-load warnings (the global-config settings warning, the workspaces-field warning) inherit the stderr routing by going through the same channel, which is why the fix lands in a channel rather than at the single call site.

Warnings emitted through the reporter stay on stdout, where the two stacks already agree — in particular the $-override deprecation warning keeps its reporter routing, because pnpm emits it through globalWarn, not the config-warnings array.

This is a pacquet-only fix: the TypeScript CLI already prints config-load warnings to stderr, so no parity work is needed on that side.

Verified against the issue's repro: pnpm install --lockfile-only 2>/dev/null now prints nothing (warning went to stderr), matching pnpm 11.

Squash Commit Body

pnpm collects warnings raised while reading config and prints them with
console.warn — to stderr, outside the reporter — while pacquet routed its
one config-load warning (the ignored `pnpm` field of package.json)
through LogEvent::Global into the default reporter's stdout frame. A
script capturing stdout got the warning mixed into the command's own
output.

Add a config-warning channel (cli_args::config_warnings) that writes a
[WARN]-labelled line straight to stderr, and emit the ignored-field
warning through it. Reporter-emitted warnings stay on stdout, where the
two stacks already agree; the $-override deprecation warning keeps its
reporter routing because pnpm emits it through globalWarn, not the
config-warnings array. Future config-load warnings inherit the stderr
routing by going through the same channel.

Closes pnpm/pnpm#13361

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    (pacquet-only fix — the TypeScript CLI already prints config-load
    warnings to stderr.)
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.
  • Updated the documentation if needed. (No documentation changes needed.)

Written by an agent (Claude Code, claude-fable-5).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes

    • Configuration-load warnings (including ignored legacy pnpm settings) are now printed to stderr instead of stdout.
    • Warnings use a consistent [WARN] label and remain readable even when output wraps by terminal width.
    • When no relevant legacy settings are present (or the root manifest can’t be read), these warnings no longer appear.
  • Tests

    • Updated installation tests to assert stderr/stdout separation, labeling, and quiet cases across scenarios.

zkochan and others added 2 commits July 27, 2026 11:09
pnpm collects warnings raised while reading config and prints them with
console.warn — to stderr, outside the reporter — while pacquet routed its
one config-load warning (the ignored `pnpm` field of package.json)
through LogEvent::Global into the default reporter's stdout frame. A
script capturing stdout got the warning mixed into the command's own
output.

Add a config-warning channel (cli_args::config_warnings) that writes a
[WARN]-labelled line straight to stderr, and emit the ignored-field
warning through it. Reporter-emitted warnings stay on stdout, where the
two stacks already agree; the $-override deprecation warning keeps its
reporter routing because pnpm emits it through globalWarn, not the
config-warnings array. Future config-load warnings inherit the stderr
routing by going through the same channel.

Closes #13361

Co-Authored-By: Claude Fable 5 <[email protected]>
miette wraps the failure report at the terminal width, and the wrap
point depends on the temp-dir path the message names. With a long-enough
TMPDIR the asserted phrase gets split across lines and the verbatim
substring match fails.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 27, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a6ae55b-2d30-4fee-ba28-62a3ab03204b

📥 Commits

Reviewing files that changed from the base of the PR and between 9383602 and 0ab4aab.

📒 Files selected for processing (1)
  • pnpm/crates/cli/src/cli_args/config_warnings.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/cli/src/cli_args/config_warnings.rs

📝 Walkthrough

Walkthrough

Adds a dedicated stderr channel for configuration-load warnings, routes legacy pnpm manifest warnings through it, updates install-path callers, and adjusts tests and release metadata.

Changes

Config warning stderr routing

Layer / File(s) Summary
Dedicated stderr warning channel
pnpm/crates/cli/src/cli_args.rs, pnpm/crates/cli/src/cli_args/config_warnings.rs, .changeset/config-warnings-stderr.md
Adds emit_config_warning, which prints styled [WARN] messages to stderr, and records the change in a changeset.
Legacy warning emission plumbing
pnpm/crates/cli/src/cli_args/legacy_pnpm_field.rs, pnpm/crates/cli/src/cli_args/install.rs, pnpm/crates/cli/src/cli_args/pipelines.rs
Removes reporter callbacks from legacy pnpm-field warning functions and routes warnings through the dedicated stderr emitter in normal and up-to-date install paths.
Stream-specific validation
pnpm/crates/cli/tests/install.rs, pnpm/crates/cli/tests/custom_resolvers.rs
Updates assertions for stderr warnings, stdout install output, BOM and workspace handling, quiet cases, and wrapped error text.

Estimated code review effort: 2 (Simple) | ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Route config-load warnings to stderr independently of the reporter [#13361] ✅
Keep normal install output and reporter warnings on their existing stdout path [#13361] ✅

Possibly related PRs

  • pnpm/pnpm#13359: Introduces the legacy pnpm-field warning plumbing updated here.
  • pnpm/pnpm#13380: Modifies related manifest parsing and warning call sites, including BOM and workspace-root cases.

Suggested labels: product: pacquet

Suggested reviewers: copilot

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13361

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix pacquet CLI config-load warnings to print on stderr

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Route config-load warnings to stderr to avoid contaminating captured stdout
• Add a dedicated config-warning emitter shared by current and future warnings
• Update tests to assert warnings on stderr and harden a wrapped-diagnostic match
Diagram

graph TD
  A["Install command"] --> B["Config derivation"] --> C["Legacy pnpm-field check"] --> D["config_warnings emitter"] --> E[/"stderr"/]
  B --> F["Reporter (default)"] --> G[/"stdout"/]

  subgraph Legend
    direction LR
    _p["CLI/module"] ~~~ _io[/"I/O stream"/]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Emit directly at call sites (raw eprintln!)
  • ➕ Minimal indirection; simplest change per warning site
  • ➖ Easy to regress as new config warnings are added
  • ➖ Harder to keep formatting/color parity consistent across warnings
2. Extend reporter to support stderr warnings
  • ➕ Single logging system; potentially configurable routing/formatting
  • ➖ Higher surface area and risk (reporter contracts, framing, snapshot expectations)
  • ➖ Still needs “always-on” behavior across reporters for config-load warnings
3. Add a dedicated "config_warnings" sink interface (trait)
  • ➕ Testable and injectable; avoids hardcoding eprintln
  • ➕ Allows future redirection (e.g., JSON) without touching callers
  • ➖ More abstraction than needed for one stream write today
  • ➖ Adds API complexity across CLI wiring

Recommendation: The dedicated cli_args::config_warnings::emit_config_warning channel is the best trade-off: it centralizes stderr routing (preventing future regressions), keeps reporter semantics unchanged, and matches pnpm’s behavior (console.warn outside the reporter). The only follow-up worth considering is making the sink injectable if more config-load warnings or non-terminal outputs require richer formatting control.

Files changed (8) +100 / -60

Enhancement (1) +1 / -0
cli_args.rsRegister new config_warnings CLI module +1/-0

Register new config_warnings CLI module

• Adds the 'config_warnings' module to the CLI args module tree so it can be used by install/config reading paths.

pnpm/crates/cli/src/cli_args.rs

Bug fix (4) +37 / -18
config_warnings.rsIntroduce stderr emitter for config-load warnings +21/-0

Introduce stderr emitter for config-load warnings

• Adds 'emit_config_warning()' which prints a '[WARN]'-prefixed message directly to stderr. Color enabling is keyed off stdout TTY and NO_COLOR, matching pnpm’s chalk behavior even though output is on stderr.

pnpm/crates/cli/src/cli_args/config_warnings.rs

install.rsStop routing ignored pnpm-field warning through reporter emit +1/-1

Stop routing ignored pnpm-field warning through reporter emit

• Updates the fast-path install logic to call 'warn_ignored_pnpm_manifest_fields_in' without passing the reporter emit function, reflecting the move to direct stderr emission for config-load warnings.

pnpm/crates/cli/src/cli_args/install.rs

legacy_pnpm_field.rsEmit migrated pnpm-field warning via config_warnings stderr channel +14/-16

Emit migrated pnpm-field warning via config_warnings stderr channel

• Replaces 'LogEvent::Global' reporter emission with 'emit_config_warning()' and adjusts function signatures accordingly. Keeps behavior limited to config-load warnings and avoids mixing warnings into stdout.

pnpm/crates/cli/src/cli_args/legacy_pnpm_field.rs

pipelines.rsEmit ignored pnpm-field warning during config derivation via stderr channel +1/-1

Emit ignored pnpm-field warning during config derivation via stderr channel

• Updates 'derive_config_root_and_package_manager_to_sync' to call the legacy pnpm-field warning helper without a reporter emitter, ensuring warnings occur early and go to stderr.

pnpm/crates/cli/src/cli_args/pipelines.rs

Tests (2) +57 / -42
custom_resolvers.rsMake pnpmfile crash assertion resilient to terminal-width wrapping +5/-1

Make pnpmfile crash assertion resilient to terminal-width wrapping

• Collapses whitespace in stderr before asserting on the failure phrase so the test is stable across different temp path lengths that affect miette wrapping.

pnpm/crates/cli/tests/custom_resolvers.rs

install.rsUpdate install tests to assert config-load warnings on stderr only +52/-41

Update install tests to assert config-load warnings on stderr only

• Reworks multiple tests to look for the migrated pnpm-field warning on stderr (including the '[WARN]' label) and assert it does not appear in stdout. Keeps stdout assertions focused on command output like "Already up to date".

pnpm/crates/cli/tests/install.rs

Documentation (1) +5 / -0
config-warnings-stderr.mdAdd changeset noting config warnings now go to stderr +5/-0

Add changeset noting config warnings now go to stderr

• Introduces a patch changeset documenting that config-load warnings are printed to stderr to avoid mixing with command stdout output.

.changeset/config-warnings-stderr.md

@greptile-apps

greptile-apps Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

The previously reported stderr-failure path is fixed because the warning now uses writeln! and explicitly discards the returned I/O error, so a closed stderr no longer aborts the command; no blocking failure remains.

Reviews (2): Last reviewed commit: "fix(cli): discard a failed config-warnin..." | Re-trigger Greptile

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 27, 2026
@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.10     11.6±0.20ms    32.3 MB/sec    1.00     10.6±0.13ms    35.4 MB/sec
packument/parse                1.06     39.6±1.45µs  1675.0 MB/sec    1.00     37.4±0.33µs  1775.8 MB/sec
tarball/download_dependency    1.04      2.9±0.24ms  1511.2 KB/sec    1.00      2.8±0.12ms  1572.4 KB/sec

@qodo-code-review

qodo-code-review Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (2) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Unrelated test refactor in custom_resolvers 📘 Rule violation ⚙ Maintainability
Description
This bug-fix PR includes an unrelated change to how a separate test matches stderr output
(collapsing whitespace) that is not directly tied to the config-warning-to-stderr fix. This
increases scope and makes the bug-fix PR less focused.
Code

pnpm/crates/cli/tests/custom_resolvers.rs[R145-149]

+    // miette wraps the report at the terminal width, and where the wrap
+    // falls depends on the temp-dir path length in the message, so the
+    // phrase is matched with the wrapping collapsed.
+    let unwrapped = stderr.split_whitespace().collect::<Vec<_>>().join(" ");
+    assert!(unwrapped.contains("refresh check crashed"), "stderr: {stderr}");
Relevance

⭐⭐⭐ High

Small test-hardening change aligns with prior accepted robustness tweaks in CLI tests.

PR-#13372
PR-#13152

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2255067 requires bug-fix PRs to avoid unrelated refactors. The change in
custom_resolvers.rs modifies stderr assertion logic for miette wrapping in a different test
scenario, expanding scope beyond the described bug fix.

Rule 2255067: Bug fix changes must not include unrelated refactors or reformatting
pnpm/crates/cli/tests/custom_resolvers.rs[145-149]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A bug-fix PR should not include unrelated refactors/reformatting; the `custom_resolvers` test change is a separate robustness tweak not directly required by the config-warning stderr routing fix.

## Issue Context
The PR’s stated scope is routing config-load warnings to stderr. The changed assertion logic in `custom_resolvers.rs` addresses line-wrapping variability in a different error path.

## Fix Focus Areas
- pnpm/crates/cli/tests/custom_resolvers.rs[145-149]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. stderr warn can panic ✓ Resolved 🐞 Bug ☼ Reliability
Description
emit_config_warning uses eprintln!, which can panic if writing to stderr fails (e.g., stderr is
piped and the consumer exits early), crashing an otherwise-successful command. The default reporter
avoids this class of crash by ignoring write/flush errors when emitting output frames/lines.
Code

pnpm/crates/cli/src/cli_args/config_warnings.rs[R17-20]

+    let colors = Colors {
+        enabled: std::io::stdout().is_terminal() && std::env::var_os("NO_COLOR").is_none(),
+    };
+    eprintln!("{} {message}", colors.warn_label());
Relevance

⭐⭐ Medium

Team often hardens CLI against panics/output failures, but no direct precedent about eprintln!
broken-pipe panics.

PR-#13202

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new config-warning channel writes directly to stderr with eprintln! (panic-on-write-failure
behavior), while the default reporter’s output path explicitly discards write/flush errors
(non-panicking best-effort output), making this a regression in robustness for this warning path.

pnpm/crates/cli/src/cli_args/config_warnings.rs[13-21]
pnpm/crates/default-reporter/src/lib.rs[226-256]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`emit_config_warning()` prints via `eprintln!`, which may panic on stderr write errors (e.g., BrokenPipe when stderr is piped).

### Issue Context
This function is intended to run on every reporter/command, so it should be robust to output redirection and early-closing consumers.

### Fix Focus Areas
- pnpm/crates/cli/src/cli_args/config_warnings.rs[13-21]

### Suggested fix
- Replace `eprintln!(...)` with an explicit `writeln!(&mut stderr, ...)` and handle the returned `io::Result`.
- Common CLI approach:
 - If the error is `ErrorKind::BrokenPipe`, return early (treat as success).
 - For other I/O errors, either ignore (best-effort warning) or plumb an error return type if you want to fail fast—pick the repo’s desired CLI contract and apply consistently.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

3. Changeset missing pnpm entry 📘 Rule violation § Compliance
Description
The new changeset only bumps pacquet and does not declare a bump for pnpm, which violates the
requirement to explicitly include pnpm in changesets. This can lead to incomplete or inconsistent
release notes/versioning for the pnpm package.
Code

.changeset/config-warnings-stderr.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

⭐ Low

Close precedents rejected adding pnpm when changeset only bumps pacquet.

PR-#13404
PR-#13406
PR-#13408

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires changeset front-matter to explicitly include the pnpm package
with a valid bump type. The added changeset front-matter includes only "pacquet": patch and omits
any pnpm entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/config-warnings-stderr.md[1-3]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new changeset file does not include a `pnpm` package bump entry, which is required by the compliance checklist.

## Issue Context
This PR introduces a user-visible behavior change (routing config-load warnings to stderr) and adds a changeset, but the changeset front-matter only lists `pacquet`.

## Fix Focus Areas
- .changeset/config-warnings-stderr.md[1-3]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Jul 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.58%. Comparing base (474d1cc) to head (0ab4aab).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13416   +/-   ##
=======================================
  Coverage   87.58%   87.58%           
=======================================
  Files         544      545    +1     
  Lines       93561    93567    +6     
=======================================
+ Hits        81941    81949    +8     
+ Misses      11620    11618    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

eprintln! panics when the write fails (a closed stderr, a consumer that
exited early), which would abort an otherwise-successful command over a
nonessential warning. The reporter sinks discard their write errors; the
config-warning channel now does the same.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 27, 2026 09:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

Addressing the Qodo review findings:

  1. eprintln! can panic on a failed stderr write — fixed in 0ab4aab: the config-warning channel now writes best-effort (let _ = writeln!(stderr(), …)) and discards write errors, the same policy the reporter sinks follow. (This also resolves Greptile's P1.)

  2. "Unrelated test refactor in custom_resolvers.rs" — deliberate, and kept. The repo guide is explicit that a test failure encountered during the work must be fixed rather than ignored ("Never ignore test failures", CLAUDE.md): this test failed during the pre-hand-off just ready run because its verbatim substring assert breaks whenever the temp-dir path length shifts miette's line-wrapping. The fix is a separate, focused commit (9383602), so the bug-fix commit itself stays clean.

  3. "Changeset missing pnpm entry" — intentional and required. Per the repo's changeset policy, pnpm in changesets always means the TypeScript CLI package, and a Rust-only change must target pacquet and omit "pnpm" (CLAUDE.md, "Changesets for the Rust products"). This fix is pacquet-only — the TypeScript CLI already prints config-load warnings to stderr — so the changeset correctly names only pacquet. The precedent PRs Qodo cites (13404, 13406, 13408) rejected adding pnpm in exactly this situation.


Written by an agent (Claude Code, claude-fable-5).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 0ab4aab

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

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

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pacquet: config-load warnings go to stdout, but pnpm sends them to stderr

3 participants