Skip to content

chore: enhance logging and error handling in file manager components #2930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2025

Conversation

Kakueeen
Copy link
Contributor

@Kakueeen Kakueeen commented Jun 19, 2025

  • Improved logging statements across various modules, including connection dialogs and event handling, to provide clearer insights during operations.
  • Added checks for empty server addresses, invalid URLs, and null pointers to enhance error handling and user feedback.
  • Streamlined logging practices to ensure consistency and better maintainability throughout the file manager codebase.

Log: This commit enhances the logging and error handling mechanisms in the file manager, improving overall visibility and robustness during operations.

Summary by Sourcery

Enhance logging and error handling throughout the file manager title bar and related components to improve observability and prevent invalid operations.

Enhancements:

  • Add detailed fmDebug/fmInfo/fmWarning/fmCritical logs for key UI and event flows, including view mode switches, URL changes, search actions, tab and history operations, slider interactions, and password checks
  • Introduce null pointer and validity checks with warnings across widgets, dialogs, event handlers, and history management to prevent crashes and invalid state transitions
  • Improve validation and user feedback for operations such as password changes, server connections, URL completions, and history navigation by skipping or aborting when inputs are empty or invalid
  • Strengthen error handling around backend interactions and library loading by logging load failures, interface invalidation, and dispatch issues

Copy link

sourcery-ai bot commented Jun 19, 2025

Reviewer's Guide

This PR systematically enhances logging and error handling across the file manager titlebar plugin by inserting detailed log statements and guard clauses to validate inputs, pointers, and states, improving traceability, consistency, and robustness.

Sequence diagram for enhanced error handling in password change flow

sequenceDiagram
    actor User
    participant DPCConfirmWidget
    participant AccessControlInter
    participant FileUtils
    participant DaemonServiceIFace

    User->>DPCConfirmWidget: Clicks Save (onSaveBtnClicked)
    DPCConfirmWidget->>DPCConfirmWidget: Validate oldPwdEdit, newPwdEdit, repeatPwdEdit (log if empty)
    alt Validation fails
        DPCConfirmWidget-->>User: Show error tooltip (log reason)
    else Validation passes
        DPCConfirmWidget->>DPCConfirmWidget: checkNewPassword(), checkRepeatPassword() (log failures)
        alt Password validation fails
            DPCConfirmWidget-->>User: Show error tooltip (log reason)
        else Password validation passes
            DPCConfirmWidget->>AccessControlInter: isValid()
            alt AccessControlInter invalid
                DPCConfirmWidget-->>User: Show critical log, abort
            else AccessControlInter valid
                DPCConfirmWidget->>FileUtils: encryptString(oldPwd)
                DPCConfirmWidget->>FileUtils: encryptString(newPwd)
                DPCConfirmWidget->>AccessControlInter: asyncCall(changePwd, oldPassEnc, newPassEnc)
                AccessControlInter-->>DPCConfirmWidget: onPasswordChecked(result)
                alt Success
                    DPCConfirmWidget-->>User: Emit sigConfirmed (log success)
                else Failure
                    DPCConfirmWidget-->>User: Show warning log, show error tooltip
                end
            end
        end
    end
Loading

Sequence diagram for improved error handling in server connection dialog

sequenceDiagram
    actor User
    participant ConnectToServerDialog
    participant DialogManagerInstance
    participant QUrl
    participant Model

    User->>ConnectToServerDialog: Clicks Connect
    ConnectToServerDialog->>ConnectToServerDialog: Check serverComboBox text (log if empty)
    alt Empty server address
        ConnectToServerDialog-->>User: Close dialog, log warning
    else Not empty
        ConnectToServerDialog->>ConnectToServerDialog: getCurrentUrlString()
        ConnectToServerDialog->>QUrl: fromUserInput(url)
        ConnectToServerDialog->>ConnectToServerDialog: updateCollections(url, false)
        alt Invalid URL (host empty)
            ConnectToServerDialog->>DialogManagerInstance: showErrorDialog
            ConnectToServerDialog-->>User: Log warning
        else Valid URL
            ConnectToServerDialog-->>User: Proceed with connection (log info)
        end
    end
Loading

Class diagram for enhanced logging and error handling in OptionButtonBox and related classes

classDiagram
    class OptionButtonBox {
        +setViewOptionsButton(button)
        +setListViewButton(button)
        +setIconViewButton(button)
        +updateOptionButtonBox(parentWidth)
        +onUrlChanged(url)
    }
    class OptionButtonBoxPrivate {
        +updateCompactButton()
        +setViewMode(mode)
        +loadViewMode(url)
        +switchMode(mode)
        +initializeUi()
    }
    OptionButtonBox --> OptionButtonBoxPrivate
    OptionButtonBoxPrivate --> ViewOptionsButton
    OptionButtonBoxPrivate --> DToolButton
    OptionButtonBoxPrivate --> DConfigManager
    OptionButtonBoxPrivate --> Application
    OptionButtonBoxPrivate --> TitleBarEventCaller
    OptionButtonBoxPrivate --> QUrl
    OptionButtonBoxPrivate : +currentMode
    OptionButtonBoxPrivate : +compactButton
    OptionButtonBoxPrivate : +iconViewButton
    OptionButtonBoxPrivate : +listViewButton
    OptionButtonBoxPrivate : +treeViewButton
    OptionButtonBoxPrivate : +viewOptionsButton
    OptionButtonBoxPrivate : +currentUrl
    OptionButtonBoxPrivate : +hBoxLayout
    OptionButtonBoxPrivate : +listViewEnabled
    OptionButtonBoxPrivate : +iconViewEnabled
    OptionButtonBoxPrivate : +treeViewEnabled
    OptionButtonBoxPrivate : +isCompactMode
    OptionButtonBoxPrivate : +buttonGroup
    OptionButtonBoxPrivate : +switchMode(mode)
    OptionButtonBoxPrivate : +loadViewMode(url)
    OptionButtonBoxPrivate : +updateCompactButton()
    OptionButtonBoxPrivate : +setViewMode(mode)
    OptionButtonBoxPrivate : +initializeUi()
Loading

Class diagram for enhanced logging in DPCConfirmWidget (password dialog)

classDiagram
    class DPCConfirmWidget {
        +initLibrary()
        +checkRepeatPassword()
        +checkNewPassword()
        +checkPasswdComplexity(pwd, msg)
        +onEditingFinished()
        +onSaveBtnClicked()
        +onPasswordChecked(result)
    }
    DPCConfirmWidget --> DeepinPwdCheck
    DPCConfirmWidget --> AccessControlInter
    DPCConfirmWidget --> FileUtils
    DPCConfirmWidget : +oldPwdEdit
    DPCConfirmWidget : +newPwdEdit
    DPCConfirmWidget : +repeatPwdEdit
    DPCConfirmWidget : +deepinPwCheck
    DPCConfirmWidget : +getPasswdLevel
    DPCConfirmWidget : +errToString
    DPCConfirmWidget : +accessControlInter
    DPCConfirmWidget : +showToolTips(msg, widget)
    DPCConfirmWidget : +setEnabled(bool)
    DPCConfirmWidget : +sigConfirmed()
Loading

File-Level Changes

Change Details Files
Inserted comprehensive logging statements for operations and state changes across the titlebar plugin
  • Added debug/info logs around key state transitions and user actions
  • Logged warnings on unexpected or invalid states
  • Logged critical errors for unrecoverable failures
views/optionbuttonbox.cpp
views/searcheditwidget.cpp
events/titlebareventreceiver.cpp
utils/historystack.cpp
dialogs/dpcconfirmwidget.cpp
Added guard clauses and early returns with logging to validate pointers, inputs, and indices
  • Null-checks on UI widgets and buttons with warning logs
  • Index/range validation in tab and history navigation
  • URL validity and empty-string checks before operations
views/tabbar.cpp
views/urlpushbutton.cpp
views/addressbar.cpp
utils/historystack.cpp
views/optionbuttonbox.cpp
Enhanced error handling and logging in password change flows
  • Checked library load and function resolution with warnings
  • Logged results of password complexity and repeat-match checks
  • Logged service calls and error codes on password change
dialogs/dpcconfirmwidget.cpp
Improved server connection dialog validation and logging
  • Warned on empty server address and invalid URL schemes
  • Logged connection attempts and favorite-addition actions
  • Skipped and logged malformed history entries
dialogs/connecttoserverdialog.cpp
Streamlined and logged configuration-driven view mode and options behavior
  • Logged tree-view enable/disable decisions and view-mode switches
  • Logged changes to preview visibility, icon size, grid density, and list height
  • Applied and logged button-visibility state from config
views/optionbuttonbox.cpp
views/viewoptionswidget.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Kakueeen - I've reviewed your changes - here's some feedback:

  • Consider consolidating the many repetitive null-pointer checks and fmWarning/fmDebug calls into helper functions or macros to reduce boilerplate and improve maintainability.
  • Standardize log message format (capitalization, punctuation, including context identifiers) and ensure consistent use of fmInfo/fmWarning/fmCritical levels to avoid confusion and log noise.
  • Audit the overall log verbosity—too many debug statements in hot code paths can flood logs and impact performance; consider dialing back or grouping lower-priority messages.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider consolidating the many repetitive null-pointer checks and fmWarning/fmDebug calls into helper functions or macros to reduce boilerplate and improve maintainability.
- Standardize log message format (capitalization, punctuation, including context identifiers) and ensure consistent use of fmInfo/fmWarning/fmCritical levels to avoid confusion and log noise.
- Audit the overall log verbosity—too many debug statements in hot code paths can flood logs and impact performance; consider dialing back or grouping lower-priority messages.

## Individual Comments

### Comment 1
<location> `src/plugins/filemanager/dfmplugin-titlebar/views/optionbuttonbox.cpp:44` </location>
<code_context>
 {
-    if (!compactButton)
+    if (!compactButton) {
+        fmWarning() << "Compact button is null, cannot update";
         return;
+    }
</code_context>

<issue_to_address>
Consider using a more specific log level for non-critical UI state.

'Warning' may be too severe here; use 'Debug' or 'Info' if the missing element is expected in some cases to avoid unnecessary log noise.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    if (!compactButton) {
        fmWarning() << "Compact button is null, cannot update";
        return;
    }
=======
    if (!compactButton) {
        fmDebug() << "Compact button is null, cannot update";
        return;
    }
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/plugins/filemanager/dfmplugin-titlebar/views/optionbuttonbox.cpp:60` </location>
<code_context>
         compactButton->setIcon(QIcon::fromTheme("dfm_viewlist_tree"));
         break;
     default:
+        fmWarning() << "Unknown view mode for compact button:" << int(currentMode);
         break;
     }
</code_context>

<issue_to_address>
Unknown view mode should be handled more explicitly.

Consider adding an assertion or fallback to handle unknown view modes and avoid silent failures.
</issue_to_address>

### Comment 3
<location> `src/plugins/filemanager/dfmplugin-titlebar/views/crumbbar.cpp:436` </location>
<code_context>
     if (!d->crumbController) {
-        fmWarning("No controller found when trying to call DFMCrumbBar::updateCrumbs() !!!");
-        fmDebug() << "updateCrumbs (no controller) : " << url;
+        fmCritical() << "Cannot update crumbs: no controller available for URL" << url.toString();
         return;
     }
</code_context>

<issue_to_address>
Critical log for missing crumb controller may be too severe.

If this is expected in normal scenarios, consider lowering the log level or handling it more gracefully.
</issue_to_address>

### Comment 4
<location> `src/plugins/filemanager/dfmplugin-titlebar/views/viewoptionsbutton.cpp:71` </location>
<code_context>
     DToolButton::setVisible(visible);
-    if (!DConfigManager::instance()->value(kViewDConfName, kDisplayPreviewVisibleKey).toBool())
+    if (!DConfigManager::instance()->value(kViewDConfName, kDisplayPreviewVisibleKey).toBool()) {
+        fmDebug() << "Display preview is disabled in config, skipping preview visibility change";
         return;
+    }
</code_context>

<issue_to_address>
Debug log may be unnecessary for expected configuration states.

If this branch is common, consider removing or reducing the log level to prevent excessive debug output.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +43 to +46
if (!compactButton) {
fmWarning() << "Compact button is null, cannot update";
return;
}
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider using a more specific log level for non-critical UI state.

'Warning' may be too severe here; use 'Debug' or 'Info' if the missing element is expected in some cases to avoid unnecessary log noise.

Suggested change
if (!compactButton) {
fmWarning() << "Compact button is null, cannot update";
return;
}
if (!compactButton) {
fmDebug() << "Compact button is null, cannot update";
return;
}

@@ -55,14 +57,15 @@ void OptionButtonBoxPrivate::updateCompactButton()
compactButton->setIcon(QIcon::fromTheme("dfm_viewlist_tree"));
break;
default:
fmWarning() << "Unknown view mode for compact button:" << int(currentMode);
Copy link

Choose a reason for hiding this comment

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

suggestion: Unknown view mode should be handled more explicitly.

Consider adding an assertion or fallback to handle unknown view modes and avoid silent failures.

@@ -433,8 +433,7 @@ void CrumbBar::onHideAddrAndUpdateCrumbs(const QUrl &url)
if (updataFlag)
update();
if (!d->crumbController) {
fmWarning("No controller found when trying to call DFMCrumbBar::updateCrumbs() !!!");
fmDebug() << "updateCrumbs (no controller) : " << url;
fmCritical() << "Cannot update crumbs: no controller available for URL" << url.toString();
Copy link

Choose a reason for hiding this comment

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

suggestion: Critical log for missing crumb controller may be too severe.

If this is expected in normal scenarios, consider lowering the log level or handling it more gracefully.

@@ -67,8 +67,10 @@ void ViewOptionsButton::switchMode(ViewMode mode, const QUrl &url)
void ViewOptionsButton::setVisible(bool visible)
{
DToolButton::setVisible(visible);
if (!DConfigManager::instance()->value(kViewDConfName, kDisplayPreviewVisibleKey).toBool())
if (!DConfigManager::instance()->value(kViewDConfName, kDisplayPreviewVisibleKey).toBool()) {
fmDebug() << "Display preview is disabled in config, skipping preview visibility change";
Copy link

Choose a reason for hiding this comment

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

nitpick: Debug log may be unnecessary for expected configuration states.

If this branch is common, consider removing or reducing the log level to prevent excessive debug output.

Kakueeen added 3 commits June 20, 2025 14:19
- Improved logging statements across various modules, including connection dialogs and event handling, to provide clearer insights during operations.
- Added checks for empty server addresses, invalid URLs, and null pointers to enhance error handling and user feedback.
- Streamlined logging practices to ensure consistency and better maintainability throughout the file manager codebase.

Log: This commit enhances the logging and error handling mechanisms in the file manager, improving overall visibility and robustness during operations.
- Improved logging statements to provide clearer insights during initialization, item insertion, and configuration changes.
- Added checks for unsupported entries, empty paths, and null pointers to enhance error handling and user feedback.
- Streamlined logging practices across various modules to ensure consistency and better maintainability.

Log: This commit enhances the logging and error handling mechanisms in the ProtocolDeviceDisplayManager and related components, improving overall visibility and robustness during operations.
- Improved logging statements to provide clearer insights during sidebar operations, including item addition, removal, and updates.
- Added checks for null items, invalid URLs, and other edge cases to enhance error handling and user feedback.
- Streamlined logging practices across sidebar-related modules to ensure consistency and better maintainability.

Log: This commit enhances the logging and error handling mechanisms in the sidebar components, improving overall visibility and robustness during operations.
@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs, Kakueeen

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Johnson-zs
Copy link
Contributor

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jun 20, 2025

This pr force merged! (status: blocked)

@deepin-bot deepin-bot bot merged commit a095935 into linuxdeepin:master Jun 20, 2025
18 of 20 checks passed
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.

3 participants