Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nushell panic when printing empty table or array to zero column pty #15328

Open
Holi0317 opened this issue Mar 17, 2025 · 3 comments
Open

Nushell panic when printing empty table or array to zero column pty #15328

Holi0317 opened this issue Mar 17, 2025 · 3 comments
Labels
needs-triage An issue that hasn't had any proper look panic

Comments

@Holi0317
Copy link

Describe the bug

On a zero column pty, nushell would panic when running print ({}) or print ([])

How to reproduce

I'm not really familiar with how to setup pty so just grabbed a go library to do this for me. Might have easier way to replicate this bug.

  1. Setup go compiler toolchain
  2. Download zip from gist https://gist.github.com/Holi0317/07af088986c5944c15dcdb928f8e5cf1
  3. Unzip to a directory
  4. cd into the directory, run go run main.go

Output for the run is:

true
true
true
| columns | rows |
| ------- | ---- |
| 0       | 0    |
Couldn't fit table into 0 columns!
Error: 
  × Main thread panicked.
  ├─▶ at crates/nu-command/src/viewers/table.rs:1104:10
  ╰─▶ Could not create empty table placeholder
  help: set the `RUST_BACKTRACE=1` environment variable to display a
        backtrace.

Tweak the nu script in main.go, tests shows following outcome:

  • []: Panic
  • {}: Panic
  • [0]: Warning Couldn't fit table into 0 columns!
  • {a: b}: Warning Couldn't fit table into 0 columns!

Expected behavior

I expect nu to not panic in this situation. Would be better if nu can fallback zero-width pty to non-interactive environment and print tables info instead of showing a warning.

CircleCI is actually creating a zero-width pty for running commands. Not sure about other CI systems.

Configuration

key value
version 0.102.0
major 0
minor 102
patch 0
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.84.1 (e71f9a9a9 2025-01-27) (Homebrew)
cargo_version cargo 1.84.1
build_time 2025-02-04 15:49:35 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins
@Holi0317 Holi0317 added the needs-triage An issue that hasn't had any proper look label Mar 17, 2025
@fdncred
Copy link
Contributor

fdncred commented Mar 17, 2025

if there are no rows and no columns there is no place to render anything. having a terminal width is important to table structures so that it knows how to draw columns and wrap data. i'm not sure how this could work otherwise.

@Holi0317
Copy link
Author

But when nushell is running in without a pty, it actually prints out the table. Maybe we should reuse that special handling for 0-wdith pty?

Easiest way to reproduce this is inside docker without -it flag:

docker run --rm ghcr.io/nushell/nushell:0.102.0-alpine -c "print (term size); print (is-terminal --stdout)"

╭─────────┬───╮
│ columns │ 0 │
│ rows    │ 0 │
╰─────────┴───╯
false

Not sure what size it's assuming pty is. Tried to print a wide table but the width is 92

docker run --rm ghcr.io/nushell/nushell:0.102.0-alpine -c "print (scope commands)"

╭─────┬──────────────────────┬──────────────────────┬────────────────────┬─────╮
│   # │         name         │       category       │     signatures     │ ... │
├─────┼──────────────────────┼──────────────────────┼────────────────────┼─────┤
│   0 │ alias                │ core                 │ {record 1 field}   │ ... │
│   1 │ all                  │ filters              │ {record 1 field}   │ ... │
│   2 │ ansi                 │ platform             │ {record 1 field}   │ ... │
│   3 │ ansi gradient        │ platform             │ {record 4 fields}  │ ... │
│   4 │ ansi link            │ platform             │ {record 4 fields}  │ ... │
│   5 │ ansi strip           │ platform             │ {record 4 fields}  │ ... │

...

@fdncred
Copy link
Contributor

fdncred commented Mar 17, 2025

I really have no idea how output can work with 0 columns and 0 rows. I mean, I believe what you're saying. I'm just not sure how that works because the table command has to know how wide the table is to draw it. I'm sure it has defaults which I thought were 80x24 but could be wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage An issue that hasn't had any proper look panic
Projects
None yet
Development

No branches or pull requests

3 participants