sgreben / jp

dead simple terminal plots from JSON data. single binary, no dependencies. linux, osx, windows.
MIT License
1.32k stars 33 forks source link

null input causes panic: reflect: call of reflect.Value.Interface on zero Value #3

Closed vielmetti closed 6 years ago

vielmetti commented 6 years ago
Eds-MacBook-Pro:~ ed$ echo "" | go/bin/jp
2018/03/22 15:23:37 EOF

panic: reflect: call of reflect.Value.Interface on zero Value

goroutine 1 [running]:
reflect.valueInterface(0x0, 0x0, 0x0, 0x10e2301, 0x1104540, 0x11f8c18)
    /usr/local/Cellar/go/1.9.3/libexec/src/reflect/value.go:936 +0x1bf
reflect.Value.Interface(0x0, 0x0, 0x0, 0x1, 0x1)
    /usr/local/Cellar/go/1.9.3/libexec/src/reflect/value.go:931 +0x44
main.linePlotData(0xc42008c200, 0x1, 0x1, 0xc42008c240, 0x1, 0x1, 0x0, 0x1, 0x0, 0xc42003be90, ...)
    /Users/ed/go/src/github.com/sgreben/jp/cmd/jp/line.go:13 +0xc5
main.linePlot(0xc42008c200, 0x1, 0x1, 0xc42008c240, 0x1, 0x1, 0xb6, 0x36, 0x11136c0, 0xc42007a501)
    /Users/ed/go/src/github.com/sgreben/jp/cmd/jp/line.go:31 +0x81
main.main()
    /Users/ed/go/src/github.com/sgreben/jp/cmd/jp/main.go:105 +0x22e

I'm not 100% sure what the right behavior is in the face of a zero-length input file, but a panic is probably not the right thing do to.

sgreben commented 6 years ago

Heh, yeah. Definitely a bug. Thanks for finding this one! I think a plot with no points would be the correct output.

sgreben commented 6 years ago

Should be fixed in 1.0.1:

echo "" | jp 
2018/03/22 21:09:59 EOF

-Inf│
    │
    │
    │
    y
    │
    │
    │
+Inf└─────x─────────
     +Inf       -Inf
vielmetti commented 6 years ago

Tested from source on Mac, and from binaries on arm64, seems to work as expected.