Nushell panic when printing empty table or array to zero column pty
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.
- Setup go compiler toolchain
- Download zip from gist https://gist.github.com/Holi0317/07af088986c5944c15dcdb928f8e5cf1
- Unzip to a directory
- 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]: WarningCouldn't fit table into 0 columns!{a: b}: WarningCouldn'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 |
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.
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} │ ... │
...
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.
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?
for what it's worth, there's a fairly easy workaround which is to | cat the nu invocation to force the pty out of relevance. at least, that worked for me.