From 0b2bf3d73a7e842957bba66894761fddf7ff2c42 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 8 Jun 2021 15:57:56 +0100 Subject: [PATCH] gron: Handle invalid input gracefully Print an error and return 1, instead of asserting. --- Userland/Utilities/gron.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/gron.cpp b/Userland/Utilities/gron.cpp index 0073da1ca1..b24eabd3eb 100644 --- a/Userland/Utilities/gron.cpp +++ b/Userland/Utilities/gron.cpp @@ -70,7 +70,15 @@ int main(int argc, char** argv) auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + + if (!json.has_value()) { + if (path) { + warnln("Failed to parse '{}' as JSON", path); + } else { + warnln("Failed to parse stdin as JSON"); + } + return 1; + } if (use_color) { color_name = "\033[33;1m";