summaryrefslogtreecommitdiff
path: root/Userland/Applets
diff options
context:
space:
mode:
authorcreator1creeper1 <creator1creeper1@airmail.cc>2022-01-06 20:32:04 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-11 09:19:09 -0800
commitb4eed2587203f18aafd3e8c0e4eb23b719bd869e (patch)
tree1025dfdca13bd1224bd213421fa9aa2d68ac7e78 /Userland/Applets
parent0d328f3c86a421089720883864d363dad2f88d25 (diff)
downloadserenity-b4eed2587203f18aafd3e8c0e4eb23b719bd869e.zip
Applets/ResourceGraph: Propagate errors in create_applet
We now return an error if we fail to parse the applet spec in the expected format. We can now also use try_set_main_widget instead of set_main_widget.
Diffstat (limited to 'Userland/Applets')
-rw-r--r--Userland/Applets/ResourceGraph/main.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/Userland/Applets/ResourceGraph/main.cpp b/Userland/Applets/ResourceGraph/main.cpp
index 1132affe50..3da6bc2841 100644
--- a/Userland/Applets/ResourceGraph/main.cpp
+++ b/Userland/Applets/ResourceGraph/main.cpp
@@ -211,13 +211,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
NonnullRefPtrVector<GUI::Window> applet_windows;
- auto create_applet = [&](GraphType graph_type, StringView spec) {
+ auto create_applet = [&](GraphType graph_type, StringView spec) -> ErrorOr<void> {
auto parts = spec.split_view(',');
dbgln("Create applet: {} with spec '{}'", (int)graph_type, spec);
if (parts.size() != 2)
- return;
+ return Error::from_string_literal("ResourceGraph: Applet spec is not composed of exactly 2 comma-separated parts"sv);
auto name = parts[0];
auto graph_color = Gfx::Color::from_string(parts[1]);
@@ -227,15 +227,17 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_window_type(GUI::WindowType::Applet);
window->resize(GraphWidget::history_size + 2, 15);
- window->set_main_widget<GraphWidget>(graph_type, graph_color, Optional<Gfx::Color> {});
+ auto graph_widget = TRY(window->try_set_main_widget<GraphWidget>(graph_type, graph_color, Optional<Gfx::Color> {}));
window->show();
applet_windows.append(move(window));
+
+ return {};
};
if (cpu)
- create_applet(GraphType::CPU, cpu);
+ TRY(create_applet(GraphType::CPU, cpu));
if (memory)
- create_applet(GraphType::Memory, memory);
+ TRY(create_applet(GraphType::Memory, memory));
TRY(Core::System::unveil("/res", "r"));
TRY(Core::System::unveil("/proc/stat", "r"));