wballard / starphleet

19 stars 37 forks source link

improved error messages for fromJson #402

Open fearphage opened 5 years ago

fearphage commented 5 years ago

I made the errors from fromJson more informative:

➜  starphleet git:(sixteen-oh-four) ✗ bash meh.sh test
fromJson(meh.sh): error reading key (test) from json ({"json":"here","cat":"pants"})

➜  starphleet git:(better-error-msgs) bash meh.sh cat
fromJson(meh.sh): This isn't json! -- {"not": "json"

The goal was for the file name to be the orders file, but I'm not really sure how it's called or if that is the first (0th) parameter even. It was an attempt at making the messages more meaningful.

FYI This is the contents of meh.sh which I assume sort of mimics the way orders are run, but I'm not a starphleet-ologist yet so ¯\_(ツ)_/¯ :

source ~/.functions

from-json '{"json":"here","cat":"pants"}' $1
fearphage commented 5 years ago

I changed the error messages to not send the json blob. So it's just the file name and at most the json key name now.

➜  starphleet git:(fromJson-errors) bash meh.sh '{"json":"here","cat":"pants"}' test
fromJson(meh.sh): error reading key (test) from json

➜  starphleet git:(fromJson-errors) bash meh.sh '{"json":"here","cat":"pants"' test
fromJson(meh.sh): This isn't json!