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 · 4 comments
Open

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

Holi0317 opened this issue Mar 17, 2025 · 4 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.

@oderwat
Copy link

oderwat commented Mar 27, 2025

I have a similar problem. When I use "nu -c 'echo "test"' inside a act workflow (inside a gitea ci chain) I get this error from nushell while I can run everything else just fine.

This is what I run

      - name: versions
        run: |
          gleam --version
          rebar3 --version
          echo "q()." | erl 2>&1 | head -1
          ssh -V
          echo -n "nushell v" && nu --version
          nu -c 'echo "{ foo:1, bar: \"test\" }" | from json'
          docker run hello-world

This is what I get from this:

| gleam 1.9.1
| rebar 3.24.0 on Erlang/OTP 27 Erts 15.2.3
| Erlang/OTP 27 [erts-15.2.3] [source] [64-bit] [smp:14:14] [ds:14:14:10] [async-threads:1] [jit]
| OpenSSH_9.2p1 Debian-2+deb12u5, OpenSSL 3.0.15 3 Sep 2024
| nushell v0.103.0
| Couldn't fit table into 0 columns!
|
| Hello from Docker!
| This message shows that your installation appears to be working correctly.
|
| To generate this message, Docker took the following steps:
|  1. The Docker client contacted the Docker daemon.
|  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
|     (arm64v8)

Clearly Nushell is the black sheep here and not useable in a CI workflow which is a shame!

Maybe we could for a size using some command? Could be handy in other cases too.

EDIT:
A work around that lets me at least get some somehow useful output is adding | to text at the end.

      - name: Nushell Script
        shell: "nu -c 'source {0}'"
        run: |
          echo "{ foo:1, bar: \"test\" }" | from json | to text

Maybe we could get some "to tty 80 25" that renders it to text with that size?

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

4 participants