Skip to content

Conversation

Jack251970
Copy link
Member

@Jack251970 Jack251970 commented Sep 15, 2025

Catch exception when creating setting panel

Catch exception when creating setting panel and display the exception for reporting.

Test

image

@github-actions github-actions bot added this to the 2.1.0 milestone Sep 15, 2025
Copy link

gitstream-cm bot commented Sep 15, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

@coderabbitai coderabbitai bot added the bug Something isn't working label Sep 15, 2025
@Jack251970 Jack251970 added enhancement New feature or request and removed bug Something isn't working labels Sep 15, 2025
Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Add guarded creation for plugin setting panels: introduce TryCreateSettingPanel to catch exceptions and return a fallback error UserControl; add two resource-backed margin fields and a logging/class-name constant; add a localization string for the error message.

Changes

Cohort / File(s) Summary
Plugin setting panel creation and fallback UI
Flow.Launcher/ViewModel/PluginViewModel.cs
- Add using System; and two private static resource-backed margins (SettingPanelMargin, SettingPanelItemTopBottomMargin).
- Add private static readonly string ClassName = nameof(PluginViewModel); for logging context.
- Replace direct setting-panel creation in SettingControl with a guarded TryCreateSettingPanel(PluginPair) helper.
- Implement TryCreateSettingPanel to call ((ISettingProvider)pair.Plugin).CreateSettingPanel(); on exception log via App.API.LogException(...), build a translated error message via App.API.GetTranslation("errorCreatingSettingPanel") (including plugin name and exception message separated by Environment.NewLine), and return a fallback UserControl containing a Grid with a read-only, wrapping TextBox styled with the margins and Color04B.
Localization
Flow.Launcher/Languages/en.xaml
- Add errorCreatingSettingPanel string: Error creating setting panel for plugin {0}:{1}{2}.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as UI
  participant PVM as PluginViewModel
  participant Plug as Plugin (ISettingProvider)

  UI->>PVM: Request SettingControl
  alt plugin provides settings
    PVM->>PVM: TryCreateSettingPanel(pair)
    PVM->>Plug: CreateSettingPanel()
    alt Create succeeds
      Plug-->>PVM: Control
      PVM-->>UI: Control
    else Create throws
      PVM->>PVM: App.API.LogException(...)
      PVM->>PVM: Build translated error message
      PVM->>PVM: Build fallback UserControl (Grid + TextBox), apply margins & Color04B
      PVM-->>UI: Fallback UserControl
    end
  else plugin has no settings
    PVM-->>UI: null / default
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jjw24
  • VictoriousRaptor

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Catch exception when creating setting panel" is a concise, single-sentence summary that directly describes the primary change (adding guarded creation and an error UI when building plugin setting panels) shown in the diff and PR objectives, so it accurately represents the main intent of the changeset.
Description Check ✅ Passed The PR description states the change (catch exceptions when creating the setting panel and display the exception for reporting) and includes a test screenshot, which is directly related to the code changes and objectives in the PR, so it is sufficiently on-topic for this lenient check.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch try_create_setting_panel

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (1)

141-171: Polish the fallback UI: fix Foreground DP, use dynamic resources, and show full exception + scroll

  • Use Control.ForegroundProperty on TextBox; TextBlock.ForegroundProperty won’t affect TextBox.
  • Bind margins via SetResourceReference so theme changes propagate.
  • Show e.ToString() for actionable stack traces.
  • Add scrollbars for long exceptions.

Apply this diff:

         private static Control TryCreateSettingPanel(PluginPair pair)
         {
             try
             {
                 // We can safely cast here as we already check this in HasSettingControl
                 return ((ISettingProvider)pair.Plugin).CreateSettingPanel();
             }
             catch (System.Exception e)
             {
-                var errorMsg = $"Error creating setting panel for plugin {pair.Metadata}\n{e.Message}";
-                var grid = new Grid()
-                {
-                    Margin = SettingPanelMargin
-                };
+                var errorMsg = $"Error creating setting panel for plugin {pair.Metadata}{System.Environment.NewLine}{e}";
+                var grid = new Grid();
+                grid.SetResourceReference(FrameworkElement.MarginProperty, "SettingPanelMargin");
                 var textBox = new TextBox
                 {
                     Text = errorMsg,
                     IsReadOnly = true,
                     HorizontalAlignment = HorizontalAlignment.Stretch,
                     VerticalAlignment = VerticalAlignment.Top,
                     TextWrapping = TextWrapping.Wrap,
-                    Margin = SettingPanelItemTopBottomMargin
+                    AcceptsReturn = true
                 };
-                textBox.SetResourceReference(TextBlock.ForegroundProperty, "Color04B");
+                textBox.SetResourceReference(FrameworkElement.MarginProperty, "SettingPanelItemTopBottomMargin");
+                textBox.SetResourceReference(Control.ForegroundProperty, "Color04B");
+                textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
+                textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
                 grid.Children.Add(textBox);
                 return new UserControl
                 {
                     Content = grid
                 };
             }
         }

Optionally, also log the exception to the app’s logger so it’s captured even if the panel isn’t open.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51df66e and e204daa.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (2)
Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs (1)
  • Control (155-496)
Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (1)
  • Control (144-147)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (1)

134-136: Guarded panel creation: good change

Using a guarded creator here avoids UI breakage when plugins misbehave. Caching via ??= preserves prior behavior.

@coderabbitai coderabbitai bot added the bug Something isn't working label Sep 15, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
Flow.Launcher/Languages/en.xaml (1)

222-222: Confirm placeholder order and propagate to other locales

Looks good. Please verify the call site passes args in this order: pluginName → Environment.NewLine → exceptionMessage. Also add this key to other language resource files (or confirm fallback behavior).

If you want a blank line before details (matching patterns elsewhere), consider:

-    <system:String x:Key="errorCreatingSettingPanel">Error creating setting panel for plugin {0}:{1}{2}</system:String>
+    <system:String x:Key="errorCreatingSettingPanel">Error creating setting panel for plugin {0}:{1}{1}{2}</system:String>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e204daa and 0355993.

📒 Files selected for processing (2)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/ViewModel/PluginViewModel.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build

Copy link

gitstream-cm bot commented Sep 15, 2025

🥷 Code experts: onesounds

Jack251970 has most 👩‍💻 activity in the files.
Jack251970, onesounds have most 🧠 knowledge in the files.

See details

Flow.Launcher/Languages/en.xaml

Activity based on git-commit:

Jack251970
SEP 9 additions & 5 deletions
AUG 4 additions & 0 deletions
JUL 48 additions & 13 deletions
JUN 21 additions & 0 deletions
MAY 33 additions & 4 deletions
APR 22 additions & 21 deletions

Knowledge based on git-blame:
onesounds: 36%
Jack251970: 22%

Flow.Launcher/ViewModel/PluginViewModel.cs

Activity based on git-commit:

Jack251970
SEP
AUG 6 additions & 1 deletions
JUL
JUN 3 additions & 3 deletions
MAY 19 additions & 25 deletions
APR 38 additions & 54 deletions

Knowledge based on git-blame:
Jack251970: 48%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (1)

142-143: Avoid static resource lookups at type init; use dynamic resource bindings

Application.Current.FindResource in static fields can throw before resources load (design-time/tests) and prevents live theme updates. Bind margins dynamically on the created elements instead.

-        private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
-        private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin");
@@
-                var grid = new Grid()
-                {
-                    Margin = SettingPanelMargin
-                };
+                var grid = new Grid();
+                grid.SetResourceReference(FrameworkElement.MarginProperty, "SettingPanelMargin");
@@
-                var textBox = new TextBox
-                {
-                    Text = errorMsg,
-                    IsReadOnly = true,
-                    HorizontalAlignment = HorizontalAlignment.Stretch,
-                    VerticalAlignment = VerticalAlignment.Top,
-                    TextWrapping = TextWrapping.Wrap,
-                    Margin = SettingPanelItemTopBottomMargin
-                };
+                var textBox = new TextBox
+                {
+                    Text = errorMsg,
+                    IsReadOnly = true,
+                    HorizontalAlignment = HorizontalAlignment.Stretch,
+                    VerticalAlignment = VerticalAlignment.Top,
+                    TextWrapping = TextWrapping.Wrap
+                };
+                textBox.SetResourceReference(FrameworkElement.MarginProperty, "SettingPanelItemTopBottomMargin");

Also applies to: 160-171

🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (1)

137-139: Don’t cache the error UI; allow retry on next expand

Current null-coalescing assignment (“??=”) caches the fallback error panel, preventing recovery if a transient failure occurs. Cache only when creation succeeds.

-        public Control SettingControl
-            => IsExpanded
-                ? _settingControl
-                    ??= HasSettingControl
-                        ? TryCreateSettingPanel(PluginPair)
-                        : null
-                : null;
+        public Control SettingControl
+        {
+            get
+            {
+                if (!IsExpanded) return null;
+                if (_settingControl != null) return _settingControl;
+                if (!HasSettingControl) return null;
+
+                if (TryCreateSettingPanel(PluginPair, out var panel))
+                {
+                    _settingControl = panel; // cache success only
+                }
+                return panel;
+            }
+        }
@@
-        private static Control TryCreateSettingPanel(PluginPair pair)
-        {
-            try
-            {
-                // We can safely cast here as we already check this in HasSettingControl
-                return ((ISettingProvider)pair.Plugin).CreateSettingPanel();
-            }
-            catch (Exception e)
-            {
-                // Log exception
-                App.API.LogException(ClassName, $"Failed to create setting panel for {pair.Metadata.Name}", e);
-
-                // Show error message in UI
-                var errorMsg = string.Format(App.API.GetTranslation("errorCreatingSettingPanel"),
-                    pair.Metadata.Name, Environment.NewLine, e.Message);
-                var grid = new Grid()
-                {
-                    Margin = SettingPanelMargin
-                };
-                var textBox = new TextBox
-                {
-                    Text = errorMsg,
-                    IsReadOnly = true,
-                    HorizontalAlignment = HorizontalAlignment.Stretch,
-                    VerticalAlignment = VerticalAlignment.Top,
-                    TextWrapping = TextWrapping.Wrap,
-                    Margin = SettingPanelItemTopBottomMargin
-                };
-                textBox.SetResourceReference(TextBlock.ForegroundProperty, "Color04B");
-                grid.Children.Add(textBox);
-                return new UserControl
-                {
-                    Content = grid
-                };
-            }
-        }
+        private static bool TryCreateSettingPanel(PluginPair pair, out Control panel)
+        {
+            try
+            {
+                // Safe cast: HasSettingControl already checked
+                panel = ((ISettingProvider)pair.Plugin).CreateSettingPanel();
+                return true;
+            }
+            catch (Exception e)
+            {
+                App.API.LogException(ClassName, $"Failed to create setting panel for {pair.Metadata.Name}", e);
+
+                var errorMsg = string.Format(App.API.GetTranslation("errorCreatingSettingPanel"),
+                    pair.Metadata.Name, Environment.NewLine, e.Message);
+
+                var grid = new Grid();
+                grid.SetResourceReference(FrameworkElement.MarginProperty, "SettingPanelMargin");
+
+                var textBox = new TextBox
+                {
+                    Text = errorMsg,
+                    IsReadOnly = true,
+                    HorizontalAlignment = HorizontalAlignment.Stretch,
+                    VerticalAlignment = VerticalAlignment.Top,
+                    TextWrapping = TextWrapping.Wrap
+                };
+                textBox.SetResourceReference(FrameworkElement.MarginProperty, "SettingPanelItemTopBottomMargin");
+                textBox.SetResourceReference(Control.ForegroundProperty, "Color04B");
+
+                grid.Children.Add(textBox);
+                panel = new UserControl { Content = grid };
+                return false;
+            }
+        }

Also applies to: 144-179

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0355993 and 18c8a04.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (2)
Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs (1)
  • Control (155-496)
Flow.Launcher.Core/Plugin/JsonRPCPluginBase.cs (1)
  • Control (144-147)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (2)
Flow.Launcher/ViewModel/PluginViewModel.cs (2)

18-19: LGTM: logging context constant

Nameof-based ClassName improves log context and is resilient to refactors.


157-159: Verify translation exists in all language packs and placeholders match

en.xaml contains the key at line 222: <system:String x:Key="errorCreatingSettingPanel">Error creating setting panel for plugin {0}:{1}{2}</system:String>. Confirm this key is present in every Flow.Launcher/Languages/*.xaml and that each translation uses three placeholders in the same order ({0} then {1} then {2}); add or fix translations where missing or mismatched.

@Jack251970 Jack251970 requested a review from Copilot September 18, 2025 12:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds exception handling when creating plugin setting panels to prevent crashes and provides user-friendly error display.

  • Wraps plugin setting panel creation in try-catch block
  • Displays formatted error message in UI when panel creation fails
  • Adds logging for troubleshooting plugin issues

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Flow.Launcher/ViewModel/PluginViewModel.cs Implements exception handling with fallback UI for failed setting panel creation
Flow.Launcher/Languages/en.xaml Adds localized error message template for setting panel creation failures

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Jack251970 Jack251970 requested a review from Copilot September 18, 2025 13:13
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@Jack251970 Jack251970 requested a review from Copilot September 18, 2025 13:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (1)

22-23: Avoid resource lookups at type init; defer with Lazy or resolve at use-site

Application.Current.FindResource in static initializers can throw (design-time/tests) and blocks live theme updates if resources change. Defer lookup.

Apply this diff to make the lookups lazy and non-eager:

-        private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
-        private static readonly Thickness SettingPanelItemTopBottomMargin = (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin");
+        private static readonly Lazy<Thickness> SettingPanelMargin = new(() =>
+            (Thickness)Application.Current.FindResource("SettingPanelMargin"));
+        private static readonly Lazy<Thickness> SettingPanelItemTopBottomMargin = new(() =>
+            (Thickness)Application.Current.FindResource("SettingPanelItemTopBottomMargin"));

And update usages in CreateErrorSettingPanel (see comment below) to use .Value.

🧹 Nitpick comments (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (1)

145-162: Exception path UX/logging nits + i18n key check

  • Include plugin ID in the log for disambiguation (Flow.Launcher/ViewModel/PluginViewModel.cs — TryCreateSettingPanel):
-                App.API.LogException(ClassName, $"Failed to create setting panel for {pair.Metadata.Name}", e);
+                App.API.LogException(ClassName,
+                    $"Failed to create setting panel for {pair.Metadata.Name} ({pair.Metadata.ID})", e);
  • i18n: Flow.Launcher/Languages/en.xaml contains
    "Error creating setting panel for plugin {0}:{1}{2}" — placeholder order {0},{1},{2} matches the current Format call (name, Environment.NewLine, message). The key appears only in en.xaml; add translations to other locale files or confirm English-only.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 245c492 and 72dae63.

📒 Files selected for processing (1)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-05T11:56:27.267Z
Learnt from: Jack251970
PR: Flow-Launcher/Flow.Launcher#3593
File: Flow.Launcher/HotkeyControlDialog.xaml:6-6
Timestamp: 2025-09-05T11:56:27.267Z
Learning: In Flow.Launcher's migration to iNKORE.UI.WPF.Modern UI framework, dialog resource keys like PopuBGColor, PopupButtonAreaBGColor, PopupButtonAreaBorderColor, and PopupTextColor are provided by the iNKORE.UI.WPF.Modern framework itself, not defined locally in the codebase theme files.

Applied to files:

  • Flow.Launcher/ViewModel/PluginViewModel.cs
🧬 Code graph analysis (1)
Flow.Launcher/ViewModel/PluginViewModel.cs (2)
Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)
  • Settings (16-616)
Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs (1)
  • Control (155-496)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (4)
Flow.Launcher/ViewModel/PluginViewModel.cs (4)

1-2: LGTM: imports

Needed for Environment.NewLine and async members.


18-19: LGTM: explicit class name for logging

Keeping a constant is fine for consistency with other ViewModels.


140-142: Guarded creation in SettingControl is a good safety net

This prevents the UI from crashing on plugin panel failures and caches the result.


215-236: Use Control.ForegroundProperty; add scrollbars; use lazy Margin.Value

Replace SetResourceReference(TextBox.ForegroundProperty, "Color04B") with Control.ForegroundProperty; change Grid.Margin to SettingPanelMargin.Value and TextBox.Margin to SettingPanelItemTopBottomMargin.Value; add VerticalScrollBarVisibility = Auto and HorizontalScrollBarVisibility = Auto on the TextBox. rg shows Color04B is defined (Flow.Launcher/Resources/Light.xaml, Dark.xaml) and TextBox.ForegroundProperty is referenced at Flow.Launcher/ViewModel/PluginViewModel.cs:230 — if you keep TextBox.ForegroundProperty, confirm the project builds.

@Jack251970 Jack251970 requested a review from jjw24 September 19, 2025 08:36
@Jack251970 Jack251970 merged commit a2c11af into dev Sep 19, 2025
6 checks passed
@Jack251970 Jack251970 deleted the try_create_setting_panel branch September 19, 2025 23:53
@jjw24 jjw24 removed the bug Something isn't working label Sep 21, 2025
TBM13 pushed a commit to TBM13/Flow.Launcher that referenced this pull request Sep 23, 2025
…etting_panel

Catch exception when creating setting panel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants