1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)

Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
This commit is contained in:
Andreas Kling 2021-11-15 01:46:51 +01:00
parent 304c03f457
commit 587f9af960
54 changed files with 172 additions and 228 deletions

View file

@ -918,7 +918,7 @@ static JS::ThrowCompletionOr<JS::Value> load_json_impl(JS::VM& vm, JS::GlobalObj
return vm.throw_completion<JS::Error>(global_object, String::formatted("Failed to open '{}': {}", filename, file->error_string()));
auto file_contents = file->read_all();
auto json = JsonValue::from_string(file_contents);
if (!json.has_value())
if (json.is_error())
return vm.throw_completion<JS::SyntaxError>(global_object, JS::ErrorType::JsonMalformed);
return JS::JSONObject::parse_json_value(global_object, json.value());
}