Преглед изворни кода

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.

creator1creeper1 пре 3 година
родитељ
комит
b4eed25872
1 измењених фајлова са 7 додато и 5 уклоњено
  1. 7 5
      Userland/Applets/ResourceGraph/main.cpp

+ 7 - 5
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"));