Skip to content

add support for BUN_CONFIG_ELIDE_LINES (& fixes #16286) - #18111

Closed
martinamps wants to merge 4 commits into
oven-sh:mainfrom
martinamps:elide-lines-env-var
Closed

martinamps wants to merge 4 commits into
oven-sh:mainfrom
martinamps:elide-lines-env-var

Conversation

@martinamps

@martinamps martinamps commented Mar 12, 2025 •

Copy link
Copy Markdown
Contributor

Summary

Adds an BUN_CONFIG_ELIDE_LINES env var per this comment and fixes #16286

Repro

Script:

mkdir -p /tmp/elide && echo '{"name":"a","private":true,"workspaces":["."],"scripts":{"s":"yes l|head -5"}}' > /tmp/elide/package.json
run() { local r; r=$( (cd /tmp/elide && FORCE_COLOR=1 BUN_CONFIG_ELIDE_LINES=2 "$1" run --filter='*' s) 2>&1 | grep -oE '\[[0-9]+ lines elided\]' | head -1); echo "${r:-(no elision)}"; }
echo "bun-debug: $(run "$PWD/build/debug/bun-debug")"
echo "bun:       $(run bun)"

Output before/after:

bun-debug: [3 lines elided]
bun:       (no elision)

Cause

Not implemented

Fix

Implement support for the flag

Verification

  • Added regression tests
  • All existing tests still pass
 bun bd test test/cli/run/filter-workspace.test.ts -t elide
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test test/cli/run/filter-workspace.test.ts -t elide
bun test v1.3.11 (60619bdc)

test/cli/run/filter-workspace.test.ts:
✓ bun > elides output by default when using --filter [233.32ms]
✓ bun > respects --elide-lines argument [233.29ms]
✓ bun > --elide-lines=0 shows all output [236.42ms]

@jakeboone02

Copy link
Copy Markdown
Contributor

You should update the description to say "fixes #16286" so it gets closed as soon as this is merged.

And thanks for this!

@martinamps martinamps changed the title add support for BUN_CONFIG_ELIDE_LINES add support for BUN_CONFIG_ELIDE_LINES (& fixes #16286) Mar 12, 2025
@martinamps

Copy link
Copy Markdown
Contributor Author

aha good point, done. Hopefully gets unblocked soon cc @RiskyMH

@martinamps

Copy link
Copy Markdown
Contributor Author

sorry @Jarred-Sumner those windows ones are a pain 😁 i should've made a way to mock that behavior probably

@martinamps
martinamps force-pushed the elide-lines-env-var branch 2 times, most recently from 3182af1 to 82331bc Compare March 14, 2025 21:39
@martinamps

Copy link
Copy Markdown
Contributor Author

All passing @RiskyMH @Jarred-Sumner :) anything else I need to do on this one, especially around docs? first time changing those

@martinamps

Copy link
Copy Markdown
Contributor Author

@RiskyMH @Jarred-Sumner 👀 ?

@martinamps

Copy link
Copy Markdown
Contributor Author

bump @Jarred-Sumner @RiskyMH 🙇

@just-toby

Copy link
Copy Markdown

@martinamps thanks for this change, I'd love to see it merged! Could you please resolve the conflicts and maybe add the maintainers as reviewers explicitly? Hopefully that'll help :)

@Trosterud

Copy link
Copy Markdown

So looking forward to this 🔥

@spalger

spalger commented Mar 19, 2026

Copy link
Copy Markdown

@martinamps would be very grateful if you could get this over the line. The fact that using bun run in CI hides error messages is a trap I see people fall in over and over

…non-terminal environments (oven-sh#16286)

- add support for BUN_CONFIG_ELIDE_LINES (oven-sh#11465)
@martinamps
martinamps force-pushed the elide-lines-env-var branch from 2488bad to 1f77577 Compare April 3, 2026 03:40
@coderabbitai

coderabbitai Bot commented Apr 3, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4d72811a-1476-4c5e-b83e-7dc3f53913aa

📥 Commits

Reviewing files that changed from the base of the PR and between 60619bd and 6a0dc0c.

📒 Files selected for processing (1)
  • scripts/build/flags.ts

Walkthrough

Adds a new exported env var BUN_CONFIG_ELIDE_LINES (documented) and uses it as a fallback for --elide-lines. Adjusts runtime behavior to warn (not exit) when --elide-lines is used in non-terminal environments. Tests updated to cover env-var behavior and CLI precedence.

Changes

Cohort / File(s) Summary
Environment Variable & Docs
src/env_var.zig, docs/runtime/environment-variables.mdx
Added exported unsigned env-var BUN_CONFIG_ELIDE_LINES and documented its semantics in the runtime environment variables reference.
CLI Argument Parsing
src/cli/Arguments.zig
When --elide-lines is not provided, read BUN_CONFIG_ELIDE_LINES as a fallback for ctx.bundler_options.elide_lines in two CLI parsing sites.
Filter Run Behavior
src/cli/filter_run.zig
Replaced hard exit on --elide-lines in non-terminal environments with detection of stdout TTY (windowsIsTerminal() on Windows, Output.isStdoutTTY() elsewhere) and emit a non-fatal Output.warn(...) so execution continues when stdout is not a terminal.
Tests
test/cli/run/filter-workspace.test.ts
Refactored test helper to accept an env object and optional elideLines; removed win32-specific failure expectations; merged spawned env handling; added tests verifying BUN_CONFIG_ELIDE_LINES controls elision and that explicit --elide-lines takes precedence.
Build flags (unrelated)
scripts/build/flags.ts
Added imports and a conditional macOS linker flag that prepends -L<...>/lib/c++ derived from the configured c.cxx path when that directory exists.
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The only out-of-scope change is in scripts/build/flags.ts (adding macOS linker flags), which appears unrelated to the elide-lines feature or issue #16286. Remove the macOS linker flag changes from scripts/build/flags.ts or clarify their necessity and relation to the primary objectives.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for BUN_CONFIG_ELIDE_LINES environment variable and fixing issue #16286.
Description check ✅ Passed The PR description provides a clear summary, includes a reproducer script, explains the cause and fix, and documents verification with test results.
Linked Issues check ✅ Passed The PR addresses issue #16286 by changing --elide-lines to warn instead of error in non-terminal environments, and adds BUN_CONFIG_ELIDE_LINES support as proposed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cli/filter_run.zig`:
- Around line 553-555: The warning currently checks state.pretty_output (derived
from Output.enable_ansi_colors_stdout) which can be true when colors are forced;
instead perform a real TTY check for stdout before warning. Modify the branch
that inspects ctx.bundler_options.elide_lines and state.pretty_output to call
the platform TTY detection (e.g., use the std.os isatty/getStdOut equivalent)
and only warn when stdout is not a TTY; update the condition around
ctx.bundler_options.elide_lines to use that TTY check rather than
state.pretty_output so forced-color scenarios don't bypass the non-terminal
warning.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: f950bcff-8330-4665-b2f8-32b422547f88

📥 Commits

Reviewing files that changed from the base of the PR and between 17bd6cb and 1f77577.

📒 Files selected for processing (5)
  • docs/runtime/environment-variables.mdx
  • src/cli/Arguments.zig
  • src/cli/filter_run.zig
  • src/env_var.zig
  • test/cli/run/filter-workspace.test.ts

Comment thread src/cli/filter_run.zig Outdated
Jarred-Sumner pushed a commit that referenced this pull request Apr 8, 2026
Split out from #18111 by @martinamps.

`--elide-lines` currently exits with an error when stdout is not a
terminal, which breaks scripts that pass the flag and run in both
interactive and CI/hook contexts. The flag is already a no-op in this
case (the elision code only runs in the TTY redraw path), so the error
serves no purpose. This removes it.

Fixes #16286

---------

Co-authored-by: Martin Amps <m@rtin.so>
Co-authored-by: Martin Amps <mamps@anthropic.com>
Co-authored-by: robobun <robobun@bun.sh>
@alii

alii commented Apr 8, 2026

Copy link
Copy Markdown
Member

Split into #28978 and #28977

@alii alii closed this Apr 8, 2026
robobun pushed a commit that referenced this pull request Apr 9, 2026
Split out from #18111 by @martinamps. Adds `BUN_CONFIG_ELIDE_LINES` as
an environment-variable equivalent of `--elide-lines`, so the limit can
be set once globally instead of per command. The CLI flag takes
precedence when both are set. Closes #11465.

Rebased after #28977 landed on main (which simplified the non-terminal
error path into a silent no-op), so this branch no longer needs its own
CLI-source tracking.

Fixes on top of a straight env-var fallback:
- Consolidate the two duplicated `--elide-lines` parse blocks in
  `Arguments.zig` into a single `parseElideLinesOption` helper, called
  after `loadConfigWithCmdArgs` so CLI + env var beat bunfig.toml.
- Empty `--elide-lines ""` (e.g. `--elide-lines "$MAYBE_UNSET"`) falls
  through to the env var instead of shadowing it.
- Env-var value is clamped via `std.math.cast` rather than `@intCast`,
  so 32-bit targets don't panic on values above `maxInt(usize)`.
- `bunfig.zig` rejects negative, non-finite, fractional, and
  out-of-range `run.elide-lines` floats with an `Expected a
  non-negative integer` error. The `>=` upper bound accounts for f64
  rounding `maxInt(u64)` up to `2^64` — a strict `>` would let the
  boundary value slip into a panicking `@intFromFloat`.

Tests cover CLI vs env-var precedence, the empty-string fallback, the
bunfig fractional rejection, and the non-terminal no-op contract.
robobun pushed a commit that referenced this pull request Apr 17, 2026
Split out from #18111 by @martinamps. Adds `BUN_CONFIG_ELIDE_LINES` as
an environment-variable equivalent of `--elide-lines`, so the limit can
be set once globally instead of per command. The CLI flag takes
precedence when both are set. Closes #11465.

Rebased after #28977 landed on main (which simplified the non-terminal
error path into a silent no-op), so this branch no longer needs its own
CLI-source tracking.

Fixes on top of a straight env-var fallback:
- Consolidate the two duplicated `--elide-lines` parse blocks in
  `Arguments.zig` into a single `parseElideLinesOption` helper, called
  after `loadConfigWithCmdArgs` so CLI + env var beat bunfig.toml.
- Empty `--elide-lines ""` (e.g. `--elide-lines "$MAYBE_UNSET"`) falls
  through to the env var instead of shadowing it.
- Env-var value is clamped via `std.math.cast` rather than `@intCast`,
  so 32-bit targets don't panic on values above `maxInt(usize)`.
- `bunfig.zig` rejects negative, non-finite, fractional, and
  out-of-range `run.elide-lines` floats with an `Expected a
  non-negative integer` error. The `>=` upper bound accounts for f64
  rounding `maxInt(u64)` up to `2^64` — a strict `>` would let the
  boundary value slip into a panicking `@intFromFloat`.

Tests cover CLI vs env-var precedence, the empty-string fallback, the
bunfig fractional rejection, and the non-terminal no-op contract.
structwafel pushed a commit to structwafel/bun that referenced this pull request Apr 25, 2026
…#28977)

Split out from oven-sh#18111 by @martinamps.

`--elide-lines` currently exits with an error when stdout is not a
terminal, which breaks scripts that pass the flag and run in both
interactive and CI/hook contexts. The flag is already a no-op in this
case (the elision code only runs in the TTY redraw path), so the error
serves no purpose. This removes it.

Fixes oven-sh#16286

---------

Co-authored-by: Martin Amps <m@rtin.so>
Co-authored-by: Martin Amps <mamps@anthropic.com>
Co-authored-by: robobun <robobun@bun.sh>
Jarred-Sumner pushed a commit that referenced this pull request May 4, 2026
Split out from #18111 by @martinamps. Adds `BUN_CONFIG_ELIDE_LINES` as
an environment-variable equivalent of `--elide-lines`, so the limit can
be set once globally instead of per command. The CLI flag takes
precedence when both are set. Closes #11465.

Rebased after #28977 landed on main (which simplified the non-terminal
error path into a silent no-op), so this branch no longer needs its own
CLI-source tracking.

Fixes on top of a straight env-var fallback:
- Consolidate the two duplicated `--elide-lines` parse blocks in
  `Arguments.zig` into a single `parseElideLinesOption` helper, called
  after `loadConfigWithCmdArgs` so CLI + env var beat bunfig.toml.
- Empty `--elide-lines ""` (e.g. `--elide-lines "$MAYBE_UNSET"`) falls
  through to the env var instead of shadowing it.
- Env-var value is clamped via `std.math.cast` rather than `@intCast`,
  so 32-bit targets don't panic on values above `maxInt(usize)`.
- `bunfig.zig` rejects negative, non-finite, fractional, and
  out-of-range `run.elide-lines` floats with an `Expected a
  non-negative integer` error. The `>=` upper bound accounts for f64
  rounding `maxInt(u64)` up to `2^64` — a strict `>` would let the
  boundary value slip into a panicking `@intFromFloat`.

Tests cover CLI vs env-var precedence, the empty-string fallback, the
bunfig fractional rejection, and the non-terminal no-op contract.
xhjkl pushed a commit to xhjkl/bun that referenced this pull request May 14, 2026
…#28977)

Split out from oven-sh#18111 by @martinamps.

`--elide-lines` currently exits with an error when stdout is not a
terminal, which breaks scripts that pass the flag and run in both
interactive and CI/hook contexts. The flag is already a no-op in this
case (the elision code only runs in the TTY redraw path), so the error
serves no purpose. This removes it.

Fixes oven-sh#16286

---------

Co-authored-by: Martin Amps <m@rtin.so>
Co-authored-by: Martin Amps <mamps@anthropic.com>
Co-authored-by: robobun <robobun@bun.sh>
robobun added a commit that referenced this pull request May 30, 2026
Split out from #18111 by @martinamps. Adds `BUN_CONFIG_ELIDE_LINES` as
an environment-variable equivalent of `--elide-lines`, so the limit can
be set once globally instead of per command. The CLI flag takes
precedence when both are set. Closes #11465.

Implemented against the Rust CLI (`src/runtime/cli/Arguments.rs`,
`src/bun_core/env_var.rs`, `src/bunfig/bunfig.rs`) after the src port:
- Consolidate the two duplicated `--elide-lines` parse blocks into a
  single `parse_elide_lines_option` helper, called after
  `load_config_with_cmd_args` so CLI + env var beat `run.elide-lines`
  in bunfig.toml.
- Empty `--elide-lines ""` (e.g. `--elide-lines "$MAYBE_UNSET"`) falls
  through to the env var instead of shadowing it.
- Env var value is clamped via `usize::try_from(...).unwrap_or(usize::MAX)`
  so 32-bit targets don't lose high bits above `usize::MAX`.
- `bunfig.rs` rejects negative, non-finite, fractional, and out-of-range
  `run.elide-lines` numbers with `Expected a non-negative integer`
  instead of silently saturating/truncating via `as usize`.

Tests cover CLI vs env-var precedence, the empty-string fallback, the
bunfig fractional rejection, and the non-terminal no-op contract. The
bunfig test uses `--config=./bunfig.toml` (`=` form) because clap's
`.one_optional` does not consume a following argv element.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--elide-lines should warn or be ignored, not error, in non-terminal environments

6 participants