Skip to content

fix: replace expect() on settings save in network chooser with warnings#623

Draft
thepastaclaw wants to merge 3 commits intodashpay:v1.0-devfrom
thepastaclaw:fix/network-chooser-save-expect
Draft

fix: replace expect() on settings save in network chooser with warnings#623
thepastaclaw wants to merge 3 commits intodashpay:v1.0-devfrom
thepastaclaw:fix/network-chooser-save-expect

Conversation

@thepastaclaw
Copy link
Collaborator

@thepastaclaw thepastaclaw commented Feb 22, 2026

Replace 3 panicking expect() calls on self.save() in the network chooser screen with if let Err + tracing::warn.

Problem

The network chooser screen calls self.save().expect("Expected to save db settings") in three places — when setting the Dash-Qt path, clearing it, and toggling the overwrite-dash-conf checkbox. If the save fails (e.g., disk full, permissions), the entire application panics.

Fix

Replace each expect() with if let Err(e) = self.save() and log a warning. A failure to persist a UI preference should degrade gracefully, not crash the app.

Cherry-picked from ralph/improvements (commit 73452b6).

Validation

What was tested:

  • cargo clippy --all-features --all-targets -- -D warnings — lint check confirming no remaining expect() on save paths
  • cargo test --all-features --workspace — full workspace test suite

Results:

  • All local commands passed
  • Clippy CI check — pass (5m24s)
  • Test Suite CI check — pass (7m32s)

Environment: Local macOS arm64; GitHub Actions CI (ubuntu-latest)

Summary by CodeRabbit

  • Bug Fixes

    • Improved error recovery when selecting or clearing custom Dash-Qt paths—previous settings are preserved if save operations fail.
    • Enhanced error messaging in advanced settings to provide clearer feedback when configuration changes cannot be saved.
  • Improvements

    • Refined path display logic in the network settings screen for improved clarity.

Replace 3 panicking expect() calls on self.save() in the network
chooser screen with if-let-Err + tracing::warn. A failure to persist
a UI setting should not crash the application.

Cherry-picked from ralph/improvements (commit 73452b6).
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

The pull request improves error handling and state management in the network chooser screen. When users select or clear Dash-Qt paths or toggle the dash.conf overwrite setting, the code now preserves the previous value and reverts to it if the save operation fails, while displaying user-facing error messages.

Changes

Cohort / File(s) Summary
Error Handling & State Reversion
src/ui/network_chooser_screen.rs
Enhanced error handling for Dash-Qt path selection, path clearing, and dash.conf overwrite operations. Added temporary variables to preserve previous state values, enabling reversion on save failures while logging warnings and displaying error messages to users. Refined UI rendering logic to display paths only when they are present and non-empty.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 When paths are chosen, we tread with care,
Preserving what was, should errors appear,
If saves should stumble, we revert with grace,
And tell the user of their troubled case,
State and stability, dancing in pair! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: replacing expect() calls with warnings in the network chooser screen's settings save operations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@thepastaclaw
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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: 2

🧹 Nitpick comments (1)
src/ui/network_chooser_screen.rs (1)

891-894: New user-facing save-failure messages bypass the MessageBanner component.

The three new error strings set by this PR are displayed via a bespoke inline Frame (lines 940–957) rather than the MessageBanner component, which is the required approach for user-facing messages in src/ui/**/*.rs. The outer island_central_panel call at line 2054 already provides the correct hook for global banners.

As per coding guidelines: "User-facing messages must use the MessageBanner component from src/ui/components/message_banner.rs, with global banners rendered by island_central_panel()."

Also applies to: 919-922, 979-982

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ui/network_chooser_screen.rs` around lines 891 - 894, Replace the inline
Frame-based user-facing error strings with the MessageBanner flow: stop setting
self.custom_dash_qt_error_message directly to raw strings and instead expose an
error state that island_central_panel will render via the MessageBanner
component (use the existing MessageBanner in
src/ui/components/message_banner.rs); update where the three new error messages
are set (the places that assign custom_dash_qt_error_message and the similar
fields at the other two locations) to set a unified banner error state (or call
a helper that creates the banner message) and ensure island_central_panel reads
that state to render MessageBanner so all global user-facing messages go through
MessageBanner instead of an inline Frame.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/ui/network_chooser_screen.rs`:
- Line 913: The Clear button guard uses self.custom_dash_qt_path.is_some() which
stays true after clearing because you set it to Some(PathBuf::new()); change the
Clear button condition to match the path display check by ensuring the concrete
PathBuf is non-empty (e.g. compute the PathBuf used for display from
self.custom_dash_qt_path and guard on !file.as_os_str().is_empty()). Update the
same logic where the button is created (referencing self.custom_dash_qt_path and
the save() call) so the Clear button is only shown when an actual path is
present and save() is only invoked when clearing a non-empty path.
- Around line 971-984: The checkbox handler currently clears and reuses
custom_dash_qt_error_message causing unrelated Dash-Qt path errors to disappear
and placing the message far from the checkbox; add a new field
overwrite_dash_conf_error_message: Option<String> on the same struct, stop
clearing custom_dash_qt_error_message in the StyledCheckbox click branch, set
overwrite_dash_conf_error_message (not custom_dash_qt_error_message) when save()
returns Err(e), and render overwrite_dash_conf_error_message immediately after
the "Overwrite dash.conf" checkbox so the error message is colocated with the
control; keep the existing previous_overwrite_dash_conf rollback behavior if
save fails (refer to self.overwrite_dash_conf, self.save(), and
previous_overwrite_dash_conf).

---

Nitpick comments:
In `@src/ui/network_chooser_screen.rs`:
- Around line 891-894: Replace the inline Frame-based user-facing error strings
with the MessageBanner flow: stop setting self.custom_dash_qt_error_message
directly to raw strings and instead expose an error state that
island_central_panel will render via the MessageBanner component (use the
existing MessageBanner in src/ui/components/message_banner.rs); update where the
three new error messages are set (the places that assign
custom_dash_qt_error_message and the similar fields at the other two locations)
to set a unified banner error state (or call a helper that creates the banner
message) and ensure island_central_panel reads that state to render
MessageBanner so all global user-facing messages go through MessageBanner
instead of an inline Frame.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b71f02 and 991fd71.

📒 Files selected for processing (1)
  • src/ui/network_chooser_screen.rs

@@ -904,24 +911,33 @@ impl NetworkChooserScreen {
}

if self.custom_dash_qt_path.is_some() && ui.button("Clear").clicked() {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

"Clear" button remains visible after a successful clear due to condition mismatch.

Line 913 guards the "Clear" button with self.custom_dash_qt_path.is_some(), but after a successful clear custom_dash_qt_path is set to Some(PathBuf::new()), which still satisfies is_some(). Meanwhile, the path display at lines 928–929 correctly gates on !file.as_os_str().is_empty() and shows nothing. The result is a "Clear" button with no path shown — pressing it again is a silent no-op that still triggers a save() call.

Align the button guard with the display guard:

🛠 Proposed fix
-                    if self.custom_dash_qt_path.is_some() && ui.button("Clear").clicked() {
+                    if self.custom_dash_qt_path.as_ref().is_some_and(|p| !p.as_os_str().is_empty()) && ui.button("Clear").clicked() {

Also applies to: 928-929

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ui/network_chooser_screen.rs` at line 913, The Clear button guard uses
self.custom_dash_qt_path.is_some() which stays true after clearing because you
set it to Some(PathBuf::new()); change the Clear button condition to match the
path display check by ensuring the concrete PathBuf is non-empty (e.g. compute
the PathBuf used for display from self.custom_dash_qt_path and guard on
!file.as_os_str().is_empty()). Update the same logic where the button is created
(referencing self.custom_dash_qt_path and the save() call) so the Clear button
is only shown when an actual path is present and save() is only invoked when
clearing a non-empty path.

Comment on lines +971 to +984
let previous_overwrite_dash_conf = self.overwrite_dash_conf;
if StyledCheckbox::new(&mut self.overwrite_dash_conf, "Overwrite dash.conf")
.show(ui)
.clicked()
{
self.save().expect("Expected to save db settings");
self.custom_dash_qt_error_message = None;
if let Err(e) = self.save() {
tracing::warn!("Failed to save overwrite_dash_conf setting: {}", e);
self.custom_dash_qt_error_message = Some(
"Failed to save overwrite dash.conf setting. Please try again."
.to_string(),
);
self.overwrite_dash_conf = previous_overwrite_dash_conf;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

overwrite_dash_conf save errors appear in the wrong section and clear unrelated errors.

custom_dash_qt_error_message is rendered inside the "Dash Core Executable Path" section (lines 940–957), which sits above the "Configuration Options" separator. When the overwrite_dash_conf save fails and sets custom_dash_qt_error_message (line 979), the error banner appears far above the checkbox that triggered it, making the cause unclear to the user. Additionally, line 976 clears any pre-existing Dash-Qt path error the moment the user clicks this checkbox, even if that error is still relevant.

Consider a dedicated overwrite_dash_conf_error_message: Option<String> field rendered immediately after the checkbox, keeping errors co-located with their source.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/ui/network_chooser_screen.rs` around lines 971 - 984, The checkbox
handler currently clears and reuses custom_dash_qt_error_message causing
unrelated Dash-Qt path errors to disappear and placing the message far from the
checkbox; add a new field overwrite_dash_conf_error_message: Option<String> on
the same struct, stop clearing custom_dash_qt_error_message in the
StyledCheckbox click branch, set overwrite_dash_conf_error_message (not
custom_dash_qt_error_message) when save() returns Err(e), and render
overwrite_dash_conf_error_message immediately after the "Overwrite dash.conf"
checkbox so the error message is colocated with the control; keep the existing
previous_overwrite_dash_conf rollback behavior if save fails (refer to
self.overwrite_dash_conf, self.save(), and previous_overwrite_dash_conf).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant