Better handling of input file errors (#187)

* Handle error when no input is provided

* Improve error when input file can't be read
sleep-stdin-bug
Alexandre GUIOT--VALENTIN 2 years ago committed by GitHub
parent a68c947949
commit aa0964a12e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,6 +11,7 @@ import (
"golang.org/x/term"
"os"
"path"
"io/fs"
"runtime/pprof"
"strings"
)
@ -50,7 +51,13 @@ func main() {
filePath = os.Args[1]
f, err := os.Open(os.Args[1])
if err != nil {
panic(err)
switch err.(type) {
case *fs.PathError:
fmt.Println(err)
os.Exit(1)
default:
panic(err)
}
}
dec = json.NewDecoder(f)
args = os.Args[2:]
@ -59,6 +66,10 @@ func main() {
dec = json.NewDecoder(os.Stdin)
args = os.Args[1:]
}
if dec == nil {
fmt.Println("No input provided. Usage: `fx data.json` or `curl ... | fx`")
os.Exit(1)
}
dec.UseNumber()
jsonObject, err := parse(dec)
if err != nil {

Loading…
Cancel
Save