Skip to content

Commit

Permalink
cli: add graceful error for missing json in cli-pretty
Browse files Browse the repository at this point in the history
Print a graceful error message if the json data is missing of invalid.

Signed-off-by: Richard Alpe <[email protected]>
  • Loading branch information
rical committed Oct 3, 2023
1 parent d49822f commit 9c12f6e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions board/netconf/rootfs/lib/infix/cli-pretty
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,21 @@ def ietf_interfaces(json, name):
sys.exit(1)
return iface.pr_iface()

def main():
try:
json_data = json.load(sys.stdin)
except json.JSONDecodeError:
print("Error, invalid JSON input")
sys.exit(1)
except Exception as e:
print("Error, unexpected error parsing JSON")
sys.exit(1)

json = json.load(sys.stdin)
if args.module == "ietf-interfaces":
sys.exit(ietf_interfaces(json_data, args.name))
else:
print(f"Error, unknown module {args.module}")
sys.exit(1)

if args.module == "ietf-interfaces":
sys.exit(ietf_interfaces(json, args.name))
else:
print(f"Error, unknown module {args.module}")
sys.exit(1)
if __name__ == "__main__":
main()

0 comments on commit 9c12f6e

Please sign in to comment.