diff options
Diffstat (limited to 'Userland')
41 files changed, 71 insertions, 101 deletions
diff --git a/Userland/Applets/Network/main.cpp b/Userland/Applets/Network/main.cpp index 59e554a073..6a6877b214 100644 --- a/Userland/Applets/Network/main.cpp +++ b/Userland/Applets/Network/main.cpp @@ -115,7 +115,7 @@ private: auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); - if (!json.has_value()) + if (json.is_error()) return adapter_info.to_string(); int connected_adapters = 0; diff --git a/Userland/Applets/ResourceGraph/main.cpp b/Userland/Applets/ResourceGraph/main.cpp index 69300ccff4..9dc5bf1a50 100644 --- a/Userland/Applets/ResourceGraph/main.cpp +++ b/Userland/Applets/ResourceGraph/main.cpp @@ -135,9 +135,8 @@ private: } auto file_contents = m_proc_stat->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); - auto& obj = json.value().as_object(); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + auto const& obj = json.as_object(); total = obj.get("total_time").to_u64(); idle = obj.get("idle_time").to_u64(); return true; @@ -157,9 +156,8 @@ private: } auto file_contents = m_proc_mem->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); - auto& obj = json.value().as_object(); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + auto const& obj = json.as_object(); unsigned kmalloc_allocated = obj.get("kmalloc_allocated").to_u32(); unsigned kmalloc_available = obj.get("kmalloc_available").to_u32(); auto user_physical_allocated = obj.get("user_physical_allocated").to_u64(); diff --git a/Userland/Applications/KeyboardSettings/main.cpp b/Userland/Applications/KeyboardSettings/main.cpp index 733cd3099b..0a5d4c0843 100644 --- a/Userland/Applications/KeyboardSettings/main.cpp +++ b/Userland/Applications/KeyboardSettings/main.cpp @@ -67,9 +67,8 @@ int main(int argc, char** argv) if (!proc_keymap->open(Core::OpenMode::ReadOnly)) VERIFY_NOT_REACHED(); - auto json = JsonValue::from_string(proc_keymap->read_all()); - VERIFY(json.has_value()); - JsonObject keymap_object = json.value().as_object(); + auto json = JsonValue::from_string(proc_keymap->read_all()).release_value_but_fixme_should_propagate_errors(); + auto const& keymap_object = json.as_object(); VERIFY(keymap_object.has("keymap")); String current_keymap = keymap_object.get("keymap").to_string(); dbgln("KeyboardSettings thinks the current keymap is: {}", current_keymap); diff --git a/Userland/Applications/PixelPaint/ProjectLoader.cpp b/Userland/Applications/PixelPaint/ProjectLoader.cpp index 768918a364..c7ada507d4 100644 --- a/Userland/Applications/PixelPaint/ProjectLoader.cpp +++ b/Userland/Applications/PixelPaint/ProjectLoader.cpp @@ -26,7 +26,7 @@ ErrorOr<void> ProjectLoader::try_load_from_fd_and_close(int fd, StringView path) auto contents = file->read_all(); auto json_or_error = JsonValue::from_string(contents); - if (!json_or_error.has_value()) { + if (json_or_error.is_error()) { m_is_raw_image = true; auto mapped_file = TRY(MappedFile::map_from_fd_and_close(fd, path)); diff --git a/Userland/Applications/SpaceAnalyzer/main.cpp b/Userland/Applications/SpaceAnalyzer/main.cpp index 31b5fc1264..ec41f9d4a5 100644 --- a/Userland/Applications/SpaceAnalyzer/main.cpp +++ b/Userland/Applications/SpaceAnalyzer/main.cpp @@ -84,10 +84,9 @@ static void fill_mounts(Vector<MountInfo>& output) } auto content = file->read_all(); - auto json = JsonValue::from_string(content); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(content).release_value_but_fixme_should_propagate_errors(); - json.value().as_array().for_each([&output](auto& value) { + json.as_array().for_each([&output](auto& value) { auto& filesystem_object = value.as_object(); MountInfo mount_info; mount_info.mount_point = filesystem_object.get("mount_point").to_string(); diff --git a/Userland/Applications/Spreadsheet/ImportDialog.cpp b/Userland/Applications/Spreadsheet/ImportDialog.cpp index 3c19bbaf27..2c646bf41b 100644 --- a/Userland/Applications/Spreadsheet/ImportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ImportDialog.cpp @@ -209,7 +209,7 @@ Result<NonnullRefPtrVector<Sheet>, String> ImportDialog::make_and_run_for(String auto import_worksheet = [&]() -> Result<NonnullRefPtrVector<Sheet>, String> { auto json_value_option = JsonParser(file.read_all()).parse(); - if (!json_value_option.has_value()) { + if (json_value_option.is_error()) { StringBuilder sb; sb.append("Failed to parse "); sb.append(file.filename()); diff --git a/Userland/Applications/Spreadsheet/Spreadsheet.cpp b/Userland/Applications/Spreadsheet/Spreadsheet.cpp index 88f054652b..eeeee7670b 100644 --- a/Userland/Applications/Spreadsheet/Spreadsheet.cpp +++ b/Userland/Applications/Spreadsheet/Spreadsheet.cpp @@ -667,7 +667,7 @@ JsonObject Sheet::gather_documentation() const JsonParser parser(doc.to_string_without_side_effects()); auto doc_object = parser.parse(); - if (doc_object.has_value()) + if (!doc_object.is_error()) object.set(it.key.to_display_string(), doc_object.value()); else dbgln("Sheet::gather_documentation(): Failed to parse the documentation for '{}'!", it.key.to_display_string()); diff --git a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp index 63add03698..e9df986b3c 100644 --- a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -84,9 +84,8 @@ void MemoryStatsWidget::refresh() VERIFY_NOT_REACHED(); auto file_contents = proc_memstat->read_all(); - auto json_result = JsonValue::from_string(file_contents); - VERIFY(json_result.has_value()); - auto json = json_result.value().as_object(); + auto json_result = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + auto const& json = json_result.as_object(); [[maybe_unused]] u32 kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_u32(); u32 kmalloc_allocated = json.get("kmalloc_allocated").to_u32(); diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp index 194a9a9d4a..5166773352 100644 --- a/Userland/DevTools/Profiler/Profile.cpp +++ b/Userland/DevTools/Profiler/Profile.cpp @@ -220,7 +220,7 @@ ErrorOr<NonnullOwnPtr<Profile>> Profile::load_from_perfcore_file(StringView path auto file = TRY(Core::File::open(path, Core::OpenMode::ReadOnly)); auto json = JsonValue::from_string(file->read_all()); - if (!json.has_value() || !json.value().is_object()) + if (json.is_error() || !json.value().is_object()) return Error::from_string_literal("Invalid perfcore format (not a JSON object)"sv); auto& object = json.value().as_object(); diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index 1f99d51fef..83ce8851ce 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -144,7 +144,7 @@ private: auto request = m_socket->read(length); auto request_json = JsonValue::from_string(request); - if (!request_json.has_value() || !request_json.value().is_object()) { + if (request_json.is_error() || !request_json.value().is_object()) { dbgln("RPC client sent invalid request"); shutdown(); return; diff --git a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp index d17c88bbd6..9a9176d4a7 100644 --- a/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp +++ b/Userland/Libraries/LibCore/ProcessStatisticsReader.cpp @@ -35,7 +35,7 @@ Optional<AllProcessesStatistics> ProcessStatisticsReader::get_all(RefPtr<Core::F auto file_contents = proc_all_file->read_all(); auto json = JsonValue::from_string(file_contents); - if (!json.has_value()) + if (json.is_error()) return {}; auto& json_obj = json.value().as_object(); diff --git a/Userland/Libraries/LibCoredump/Reader.cpp b/Userland/Libraries/LibCoredump/Reader.cpp index 661d92e05d..c5126e689a 100644 --- a/Userland/Libraries/LibCoredump/Reader.cpp +++ b/Userland/Libraries/LibCoredump/Reader.cpp @@ -149,7 +149,7 @@ const JsonObject Reader::process_info() const if (!process_info_notes_entry) return {}; auto process_info_json_value = JsonValue::from_string(process_info_notes_entry->json_data); - if (!process_info_json_value.has_value()) + if (process_info_json_value.is_error()) return {}; if (!process_info_json_value.value().is_object()) return {}; @@ -247,7 +247,7 @@ HashMap<String, String> Reader::metadata() const if (!metadata_notes_entry) return {}; auto metadata_json_value = JsonValue::from_string(metadata_notes_entry->json_data); - if (!metadata_json_value.has_value()) + if (metadata_json_value.is_error()) return {}; if (!metadata_json_value.value().is_object()) return {}; diff --git a/Userland/Libraries/LibDebug/DebugSession.cpp b/Userland/Libraries/LibDebug/DebugSession.cpp index ec76677a77..b91b0b801d 100644 --- a/Userland/Libraries/LibDebug/DebugSession.cpp +++ b/Userland/Libraries/LibDebug/DebugSession.cpp @@ -405,10 +405,9 @@ void DebugSession::update_loaded_libs() VERIFY(rc); auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); - auto vm_entries = json.value().as_array(); + auto const& vm_entries = json.as_array(); Regex<PosixExtended> segment_name_re("(.+): "); auto get_path_to_object = [&segment_name_re](String const& vm_name) -> Optional<String> { diff --git a/Userland/Libraries/LibDesktop/Launcher.cpp b/Userland/Libraries/LibDesktop/Launcher.cpp index 89953ebe30..36a2af332c 100644 --- a/Userland/Libraries/LibDesktop/Launcher.cpp +++ b/Userland/Libraries/LibDesktop/Launcher.cpp @@ -17,9 +17,8 @@ namespace Desktop { auto Launcher::Details::from_details_str(const String& details_str) -> NonnullRefPtr<Details> { auto details = adopt_ref(*new Details); - auto json = JsonValue::from_string(details_str); - VERIFY(json.has_value()); - auto obj = json.value().as_object(); + auto json = JsonValue::from_string(details_str).release_value_but_fixme_should_propagate_errors(); + auto const& obj = json.as_object(); details->executable = obj.get("executable").to_string(); details->name = obj.get("name").to_string(); if (auto type_value = obj.get_ptr("type")) { diff --git a/Userland/Libraries/LibGUI/CommonLocationsProvider.cpp b/Userland/Libraries/LibGUI/CommonLocationsProvider.cpp index b23868c452..29d1f10b7f 100644 --- a/Userland/Libraries/LibGUI/CommonLocationsProvider.cpp +++ b/Userland/Libraries/LibGUI/CommonLocationsProvider.cpp @@ -45,7 +45,7 @@ void CommonLocationsProvider::load_from_json(const String& json_path) } auto json = JsonValue::from_string(file->read_all()); - if (!json.has_value()) { + if (json.is_error()) { dbgln("Common locations file {} is not a valid JSON file.", file->filename()); return; } @@ -55,7 +55,7 @@ void CommonLocationsProvider::load_from_json(const String& json_path) } s_common_locations.clear(); - auto contents = json.value().as_array(); + auto const& contents = json.value().as_array(); for (size_t i = 0; i < contents.size(); ++i) { auto entry_value = contents.at(i); if (!entry_value.is_object()) diff --git a/Userland/Libraries/LibGUI/GMLParser.cpp b/Userland/Libraries/LibGUI/GMLParser.cpp index 3a8baf25af..2ef1b995e7 100644 --- a/Userland/Libraries/LibGUI/GMLParser.cpp +++ b/Userland/Libraries/LibGUI/GMLParser.cpp @@ -94,7 +94,7 @@ static Optional<JsonValue> parse_core_object(Queue<GMLToken>& tokens) } else if (peek() == GMLToken::Type::JsonValue) { auto value_string = tokens.dequeue(); auto parsed_value = JsonValue::from_string(value_string.m_view); - if (!parsed_value.has_value()) { + if (parsed_value.is_error()) { dbgln("Expected property to be JSON value"); return {}; } diff --git a/Userland/Libraries/LibGUI/JsonArrayModel.cpp b/Userland/Libraries/LibGUI/JsonArrayModel.cpp index 409c8ed732..f5f609e50a 100644 --- a/Userland/Libraries/LibGUI/JsonArrayModel.cpp +++ b/Userland/Libraries/LibGUI/JsonArrayModel.cpp @@ -20,11 +20,10 @@ void JsonArrayModel::invalidate() return; } - auto json = JsonValue::from_string(file->read_all()); + auto json = JsonValue::from_string(file->read_all()).release_value_but_fixme_should_propagate_errors(); - VERIFY(json.has_value()); - VERIFY(json.value().is_array()); - m_array = json.value().as_array(); + VERIFY(json.is_array()); + m_array = json.as_array(); did_update(); } diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index b7f4679b1d..ac3fc9cd3f 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -352,7 +352,7 @@ JS_DEFINE_NATIVE_FUNCTION(JSONObject::parse) auto reviver = vm.argument(1); auto json = JsonValue::from_string(string); - if (!json.has_value()) + if (json.is_error()) return vm.throw_completion<SyntaxError>(global_object, ErrorType::JsonMalformed); Value unfiltered = parse_json_value(global_object, json.value()); if (reviver.is_function()) { diff --git a/Userland/Libraries/LibKeyboard/CharacterMapFile.cpp b/Userland/Libraries/LibKeyboard/CharacterMapFile.cpp index b36693c008..88f2df9b41 100644 --- a/Userland/Libraries/LibKeyboard/CharacterMapFile.cpp +++ b/Userland/Libraries/LibKeyboard/CharacterMapFile.cpp @@ -31,7 +31,7 @@ Optional<CharacterMapData> CharacterMapFile::load_from_file(const String& filena auto file_contents = file->read_all(); auto json_result = JsonValue::from_string(file_contents); - if (!json_result.has_value()) { + if (json_result.is_error()) { dbgln("Failed to load character map from file {}", path); return {}; } diff --git a/Userland/Libraries/LibSymbolication/Symbolication.cpp b/Userland/Libraries/LibSymbolication/Symbolication.cpp index 07cc2205ec..3484958218 100644 --- a/Userland/Libraries/LibSymbolication/Symbolication.cpp +++ b/Userland/Libraries/LibSymbolication/Symbolication.cpp @@ -158,7 +158,7 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid, IncludeSourcePosition in } auto json = JsonValue::from_string(file_or_error.value()->read_all()); - if (!json.has_value() || !json.value().is_array()) { + if (json.is_error() || !json.value().is_array()) { warnln("Invalid contents in {}", stack_path); return {}; } @@ -178,7 +178,7 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid, IncludeSourcePosition in } auto json = JsonValue::from_string(file_or_error.value()->read_all()); - if (!json.has_value() || !json.value().is_array()) { + if (json.is_error() || !json.value().is_array()) { warnln("Invalid contents in {}", vm_path); return {}; } diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 7993a97841..3641559c25 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -241,7 +241,7 @@ inline Optional<JsonValue> get_test_results(JS::Interpreter& interpreter) auto json_string = TRY_OR_DISCARD(JS::JSONObject::stringify_impl(interpreter.global_object(), results, JS::js_undefined(), JS::js_undefined())); auto json = JsonValue::from_string(json_string); - if (!json.has_value()) + if (json.is_error()) return {}; return json.value(); diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.h b/Userland/Libraries/LibWeb/DOMTreeModel.h index edee42e1df..3fdeeb38c8 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.h +++ b/Userland/Libraries/LibWeb/DOMTreeModel.h @@ -18,11 +18,8 @@ class DOMTreeModel final : public GUI::Model { public: static NonnullRefPtr<DOMTreeModel> create(StringView dom_tree, GUI::TreeView& tree_view) { - auto json_or_error = JsonValue::from_string(dom_tree); - if (!json_or_error.has_value()) - VERIFY_NOT_REACHED(); - - return adopt_ref(*new DOMTreeModel(json_or_error.value().as_object(), tree_view)); + auto json_or_error = JsonValue::from_string(dom_tree).release_value_but_fixme_should_propagate_errors(); + return adopt_ref(*new DOMTreeModel(json_or_error.as_object(), tree_view)); } virtual ~DOMTreeModel() override; diff --git a/Userland/Libraries/LibWeb/StylePropertiesModel.h b/Userland/Libraries/LibWeb/StylePropertiesModel.h index 8eec03e2f8..974f403a75 100644 --- a/Userland/Libraries/LibWeb/StylePropertiesModel.h +++ b/Userland/Libraries/LibWeb/StylePropertiesModel.h @@ -23,11 +23,8 @@ public: static NonnullRefPtr<StylePropertiesModel> create(StringView properties) { - auto json_or_error = JsonValue::from_string(properties); - if (!json_or_error.has_value()) - VERIFY_NOT_REACHED(); - - return adopt_ref(*new StylePropertiesModel(json_or_error.value().as_object())); + auto json_or_error = JsonValue::from_string(properties).release_value_but_fixme_should_propagate_errors(); + return adopt_ref(*new StylePropertiesModel(json_or_error.as_object())); } virtual ~StylePropertiesModel() override; diff --git a/Userland/Services/DHCPClient/DHCPv4Client.cpp b/Userland/Services/DHCPClient/DHCPv4Client.cpp index 7b9d5f2728..d17b6c5d0f 100644 --- a/Userland/Services/DHCPClient/DHCPv4Client.cpp +++ b/Userland/Services/DHCPClient/DHCPv4Client.cpp @@ -169,7 +169,7 @@ ErrorOr<DHCPv4Client::Interfaces> DHCPv4Client::get_discoverable_interfaces() auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); - if (!json.has_value() || !json.value().is_array()) { + if (json.is_error() || !json.value().is_array()) { dbgln("Error: No network adapters available"); return Error::from_string_literal("No network adapters available"sv); } diff --git a/Userland/Services/LookupServer/MulticastDNS.cpp b/Userland/Services/LookupServer/MulticastDNS.cpp index 9be2216d17..c2d3ecb98d 100644 --- a/Userland/Services/LookupServer/MulticastDNS.cpp +++ b/Userland/Services/LookupServer/MulticastDNS.cpp @@ -121,12 +121,11 @@ Vector<IPv4Address> MulticastDNS::local_addresses() const } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); Vector<IPv4Address> addresses; - json.value().as_array().for_each([&addresses](auto& value) { + json.as_array().for_each([&addresses](auto& value) { auto if_object = value.as_object(); auto address = if_object.get("ipv4_address").to_string(); auto ipv4_address = IPv4Address::from_string(address); diff --git a/Userland/Utilities/arp.cpp b/Userland/Utilities/arp.cpp index d19a89140d..1272cc51fd 100644 --- a/Userland/Utilities/arp.cpp +++ b/Userland/Utilities/arp.cpp @@ -100,10 +100,9 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); - Vector<JsonValue> sorted_regions = json.value().as_array().values(); + Vector<JsonValue> sorted_regions = json.as_array().values(); quick_sort(sorted_regions, [](auto& a, auto& b) { return a.as_object().get("ip_address").to_string() < b.as_object().get("ip_address").to_string(); }); diff --git a/Userland/Utilities/df.cpp b/Userland/Utilities/df.cpp index 91222420c6..df89529457 100644 --- a/Userland/Utilities/df.cpp +++ b/Userland/Utilities/df.cpp @@ -47,9 +47,8 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json_result = JsonValue::from_string(file_contents); - VERIFY(json_result.has_value()); - auto json = json_result.value().as_array(); + auto json_result = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + auto const& json = json_result.as_array(); json.for_each([](auto& value) { auto& fs_object = value.as_object(); auto fs = fs_object.get("class_name").to_string(); diff --git a/Userland/Utilities/fortune.cpp b/Userland/Utilities/fortune.cpp index 84efc4eede..0b9fe4b9e2 100644 --- a/Userland/Utilities/fortune.cpp +++ b/Userland/Utilities/fortune.cpp @@ -100,16 +100,16 @@ int main(int argc, char** argv) auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); - if (!json.has_value()) { + if (json.is_error()) { warnln("Couldn't parse {} as JSON", path); return 1; } - if (!json->is_array()) { + if (!json.value().is_array()) { warnln("{} does not contain an array of quotes", path); return 1; } - const auto quotes = parse_all(json->as_array()); + const auto quotes = parse_all(json.value().as_array()); if (quotes.is_empty()) { warnln("{} does not contain any valid quotes", path); return 1; diff --git a/Userland/Utilities/gron.cpp b/Userland/Utilities/gron.cpp index 95a6ac7887..390657c3c9 100644 --- a/Userland/Utilities/gron.cpp +++ b/Userland/Utilities/gron.cpp @@ -69,7 +69,7 @@ int main(int argc, char** argv) auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); - if (!json.has_value()) { + if (json.is_error()) { if (path) { warnln("Failed to parse '{}' as JSON", path); } else { diff --git a/Userland/Utilities/ifconfig.cpp b/Userland/Utilities/ifconfig.cpp index f62a971274..5fc18ee3b4 100644 --- a/Userland/Utilities/ifconfig.cpp +++ b/Userland/Utilities/ifconfig.cpp @@ -45,9 +45,8 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); - json.value().as_array().for_each([](auto& value) { + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + json.as_array().for_each([](auto& value) { auto& if_object = value.as_object(); auto name = if_object.get("name").to_string(); diff --git a/Userland/Utilities/jp.cpp b/Userland/Utilities/jp.cpp index 0685672079..7ab6099e9c 100644 --- a/Userland/Utilities/jp.cpp +++ b/Userland/Utilities/jp.cpp @@ -53,7 +53,7 @@ int main(int argc, char** argv) auto file_contents = file->read_all(); auto json = JsonValue::from_string(file_contents); - if (!json.has_value()) { + if (json.is_error()) { warnln("Couldn't parse {} as JSON", path); return 1; } diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 6c44120bd1..b8ff9b9881 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -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()); } diff --git a/Userland/Utilities/lsirq.cpp b/Userland/Utilities/lsirq.cpp index 87323c181c..0bb3e1dc72 100644 --- a/Userland/Utilities/lsirq.cpp +++ b/Userland/Utilities/lsirq.cpp @@ -39,9 +39,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) outln(" CPU0"); auto file_contents = proc_interrupts->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); - json.value().as_array().for_each([](auto& value) { + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + json.as_array().for_each([](auto& value) { auto& handler = value.as_object(); auto purpose = handler.get("purpose").to_string(); auto interrupt = handler.get("interrupt_line").to_string(); diff --git a/Userland/Utilities/lsof.cpp b/Userland/Utilities/lsof.cpp index 7daaa89b42..8690ed7018 100644 --- a/Userland/Utilities/lsof.cpp +++ b/Userland/Utilities/lsof.cpp @@ -70,15 +70,10 @@ static Vector<OpenFile> get_open_files_by_pid(pid_t pid) } auto data = file.value()->read_all(); - JsonParser parser(data); - auto result = parser.parse(); - - if (!result.has_value()) { - VERIFY_NOT_REACHED(); - } + auto json = JsonValue::from_string(data).release_value_but_fixme_should_propagate_errors(); Vector<OpenFile> files; - result.value().as_array().for_each([pid, &files](const JsonValue& object) { + json.as_array().for_each([pid, &files](const JsonValue& object) { OpenFile open_file; open_file.pid = pid; open_file.fd = object.as_object().get("fd").to_int(); diff --git a/Userland/Utilities/lspci.cpp b/Userland/Utilities/lspci.cpp index 67bd6adc80..b01dee6c3e 100644 --- a/Userland/Utilities/lspci.cpp +++ b/Userland/Utilities/lspci.cpp @@ -66,9 +66,8 @@ int main(int argc, char** argv) } auto file_contents = proc_pci->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); - json.value().as_array().for_each([db, format](auto& value) { + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); + json.as_array().for_each([db, format](auto& value) { auto& dev = value.as_object(); auto domain = dev.get("domain").to_u32(); auto bus = dev.get("bus").to_u32(); diff --git a/Userland/Utilities/lsusb.cpp b/Userland/Utilities/lsusb.cpp index 23a1dda775..5c4725c7ac 100644 --- a/Userland/Utilities/lsusb.cpp +++ b/Userland/Utilities/lsusb.cpp @@ -59,10 +59,9 @@ int main(int argc, char** argv) } auto contents = proc_usb_device->read_all(); - auto json = JsonValue::from_string(contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(contents).release_value_but_fixme_should_propagate_errors(); - json.value().as_array().for_each([usb_db](auto& value) { + json.as_array().for_each([usb_db](auto& value) { auto& device_descriptor = value.as_object(); auto device_address = device_descriptor.get("device_address").to_u32(); diff --git a/Userland/Utilities/mount.cpp b/Userland/Utilities/mount.cpp index a572c354fb..118b4941af 100644 --- a/Userland/Utilities/mount.cpp +++ b/Userland/Utilities/mount.cpp @@ -124,10 +124,9 @@ static bool print_mounts() } auto content = df->read_all(); - auto json = JsonValue::from_string(content); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(content).release_value_but_fixme_should_propagate_errors(); - json.value().as_array().for_each([](auto& value) { + json.as_array().for_each([](auto& value) { auto& fs_object = value.as_object(); auto class_name = fs_object.get("class_name").to_string(); auto mount_point = fs_object.get("mount_point").to_string(); diff --git a/Userland/Utilities/netstat.cpp b/Userland/Utilities/netstat.cpp index fc19aa1bd4..02f63def2b 100644 --- a/Userland/Utilities/netstat.cpp +++ b/Userland/Utilities/netstat.cpp @@ -156,10 +156,9 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); - Vector<JsonValue> sorted_regions = json.value().as_array().values(); + Vector<JsonValue> sorted_regions = json.as_array().values(); quick_sort(sorted_regions, [](auto& a, auto& b) { return a.as_object().get("local_port").to_u32() < b.as_object().get("local_port").to_u32(); }); @@ -210,10 +209,9 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); - Vector<JsonValue> sorted_regions = json.value().as_array().values(); + Vector<JsonValue> sorted_regions = json.as_array().values(); quick_sort(sorted_regions, [](auto& a, auto& b) { return a.as_object().get("local_port").to_u32() < b.as_object().get("local_port").to_u32(); }); diff --git a/Userland/Utilities/pmap.cpp b/Userland/Utilities/pmap.cpp index 7ad499424f..b37fdc7184 100644 --- a/Userland/Utilities/pmap.cpp +++ b/Userland/Utilities/pmap.cpp @@ -56,10 +56,9 @@ int main(int argc, char** argv) } auto file_contents = file->read_all(); - auto json = JsonValue::from_string(file_contents); - VERIFY(json.has_value()); + auto json = JsonValue::from_string(file_contents).release_value_but_fixme_should_propagate_errors(); - Vector<JsonValue> sorted_regions = json.value().as_array().values(); + Vector<JsonValue> sorted_regions = json.as_array().values(); quick_sort(sorted_regions, [](auto& a, auto& b) { return a.as_object().get("address").to_addr() < b.as_object().get("address").to_addr(); }); diff --git a/Userland/Utilities/utmpupdate.cpp b/Userland/Utilities/utmpupdate.cpp index 067a64225e..782a605708 100644 --- a/Userland/Utilities/utmpupdate.cpp +++ b/Userland/Utilities/utmpupdate.cpp @@ -63,7 +63,7 @@ int main(int argc, char** argv) JsonObject json; if (!file_contents.is_empty()) { - if (!previous_json.has_value() || !previous_json.value().is_object()) { + if (previous_json.is_error() || !previous_json.value().is_object()) { dbgln("Error: Could not parse JSON"); } else { json = previous_json.value().as_object(); diff --git a/Userland/Utilities/w.cpp b/Userland/Utilities/w.cpp index 3265eca222..ad30396efd 100644 --- a/Userland/Utilities/w.cpp +++ b/Userland/Utilities/w.cpp @@ -50,7 +50,7 @@ int main() } auto& file = *file_or_error.value(); auto json = JsonValue::from_string(file.read_all()); - if (!json.has_value() || !json.value().is_object()) { + if (json.is_error() || !json.value().is_object()) { warnln("Error: Could not parse /var/run/utmp"); return 1; } |