Skip to content

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

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 1 commit into from
Jun 17, 2025

Conversation

Kakueeen
Copy link
Contributor

@Kakueeen Kakueeen commented Jun 16, 2025

  • Improved logging statements across various file manager modules, including DragMonitor, Workspace, and menu handling, to provide clearer insights during operations.
  • Added checks and warnings for null pointers and invalid states, enhancing error handling in file operations and user interactions.
  • 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 visibility and robustness of the file manager plugin by adding comprehensive logging and error checks across core components.

Bug Fixes:

  • Add safeguards and warning logs for null QAction, invalid QModelIndex, missing views/models, and unsupported states to avoid unexpected behaviors and potential null dereferences.

Enhancements:

  • Add detailed debug, info, and warning logs in key modules such as ShortcutHelper, FileOperatorHelper, FileViewModel, FileSortWorker, RootInfo, and TraversalDirThreadManager to trace lifecycle events, operations, and thread activities.
  • Insert null-pointer and state validity checks in event handlers, menu scenes, delegates, and helpers to catch invalid actions and prevent crashes.
  • Log operation parameters and counts (e.g., number of files copied, moved to trash, deleted, or previewed) and hook handling results to improve traceability of file operations.
  • Instrument UI components (FileView, WorkspaceWidget, FileViewStatusBar, RenameBar, HeaderView) with logging for initialization, layout changes, and user interactions.
  • Streamline logging conventions across the codebase by consistently using fmDebug, fmInfo, and fmWarning for maintainable diagnostics.

Chores:

  • Consolidate logging imports and define consistent log prefixes in various modules to maintain uniformity of debug output.

- Improved logging statements across various file manager modules, including DragMonitor, Workspace, and menu handling, to provide clearer insights during operations.
- Added checks and warnings for null pointers and invalid states, enhancing error handling in file operations and user interactions.
- 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.
Copy link

sourcery-ai bot commented Jun 16, 2025

Reviewer's Guide

This PR introduces comprehensive logging across the file manager codebase—with fmDebug/fmInfo/fmWarning statements inserted in constructors, key methods, callbacks, and error paths—while adding guard checks for null or invalid inputs and standardizing log level usage. It also enriches file traversal and data-fetching modules with detailed operational tracing and context.

File-Level Changes

Change Details Files
Broad logging instrumentation added across utility and helper modules
  • Inserted debug/info logs in constructors and initialization routines
  • Instrumented shortcut, clipboard, view and workspace helpers with operation-level logs
  • Logged contextual data (counts, IDs, modes) for copy, cut, paste, delete, navigation actions
src/plugins/filemanager/dfmplugin-workspace/utils/shortcuthelper.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/fileoperatorhelper.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/fileviewhelper.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/workspacehelper.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/selecthelper.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/traversaldirthreadmanager.cpp
src/apps/dde-file-manager/dragmonitor.cpp
Added validation checks and warning logs to prevent invalid states and null pointers
  • Guarded against null event, view, action, model or index before processing
  • Early-return with warning logs on empty selections and invalid URLs
  • Warn and abort on unsupported or invalid operations (e.g., rename without selection)
src/plugins/filemanager/dfmplugin-workspace/utils/shortcuthelper.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/fileoperatorhelper.cpp
src/plugins/filemanager/dfmplugin-workspace/models/fileviewmodel.cpp
src/plugins/filemanager/dfmplugin-workspace/views/fileview.cpp
src/plugins/filemanager/dfmplugin-workspace/views/renamebar.cpp
Standardized log levels and message formats across modules
  • Replaced mixed qDebug/qWarning calls with fmDebug/fmInfo/fmWarning
  • Unified log templates and included contextual metadata
  • Ensured consistent log usage in menu scenes, status bar, delegates, and animation helpers
src/plugins/filemanager/dfmplugin-workspace/views/fileviewstatusbar.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/viewanimationhelper.cpp
src/plugins/filemanager/dfmplugin-workspace/menus/sortanddisplaymenuscene.cpp
src/plugins/filemanager/dfmplugin-workspace/views/iconitemdelegate.cpp
src/plugins/filemanager/dfmplugin-workspace/views/headerview.cpp
Enhanced tracing in data-fetch, sorting and traversal components
  • Logged cache decisions and fetch start/completion in FileDataManager
  • Traced sorting arguments, filter operations, and traversal finish states in FileSortWorker
  • Added detailed traversal-progress and async iterator logs in TraversalDirThreadManager and RootInfo
src/plugins/filemanager/dfmplugin-workspace/utils/filedatamanager.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/filesortworker.cpp
src/plugins/filemanager/dfmplugin-workspace/models/rootinfo.cpp
src/plugins/filemanager/dfmplugin-workspace/utils/traversaldirthreadmanager.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:

  • The sheer volume of debug/info logs—especially inside hot loops like file iteration and UI paint routines—could introduce performance overhead and clutter; consider auditing log levels and trimming verbosity in performance-critical paths.
  • You’ve added many null-pointer and invalid-state checks with warnings; consolidating these guards into shared helper functions or macros would reduce boilerplate and ensure consistent error handling.
  • To make post-mortem debugging easier, include consistent context (such as window IDs, URLs, or traversal tokens) in each log message and adhere strictly to structured log levels (debug/info/warning).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The sheer volume of debug/info logs—especially inside hot loops like file iteration and UI paint routines—could introduce performance overhead and clutter; consider auditing log levels and trimming verbosity in performance-critical paths.
- You’ve added many null-pointer and invalid-state checks with warnings; consolidating these guards into shared helper functions or macros would reduce boilerplate and ensure consistent error handling.
- To make post-mortem debugging easier, include consistent context (such as window IDs, URLs, or traversal tokens) in each log message and adhere strictly to structured log levels (debug/info/warning).

## Individual Comments

### Comment 1
<location> `src/plugins/filemanager/dfmplugin-workspace/utils/filedatamanager.cpp:33` </location>
<code_context>
         return rootInfoMap.value(url);
+    }

+    fmInfo() << "Creating new RootInfo for URL:" << url.toString();
     return createRoot(url);
 }
</code_context>

<issue_to_address>
Filter root creation logs or guard by level

Consider filtering these logs or using `fmDebug` to prevent excessive info-level log output during frequent navigation.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    fmInfo() << "Creating new RootInfo for URL:" << url.toString();
=======
    fmDebug() << "Creating new RootInfo for URL:" << url.toString();
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/plugins/filemanager/dfmplugin-workspace/views/iconitemdelegate.cpp:58` </location>
<code_context>
 {
     Q_D(IconItemDelegate);

+    fmInfo() << "Creating IconItemDelegate";
+
     d->expandedItem = new ExpandedItem(this, parent->parent()->viewport());
</code_context>

<issue_to_address>
Info-level log in constructor may be too coarse

Frequent delegate construction may clutter info logs; consider using `fmDebug()` for less verbosity.
</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.


fmInfo() << "Creating new RootInfo 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: Filter root creation logs or guard by level

Consider filtering these logs or using fmDebug to prevent excessive info-level log output during frequent navigation.

Suggested change
fmInfo() << "Creating new RootInfo for URL:" << url.toString();
fmDebug() << "Creating new RootInfo for URL:" << url.toString();

@@ -55,12 +55,17 @@ IconItemDelegate::IconItemDelegate(FileViewHelper *parent)
{
Q_D(IconItemDelegate);

fmInfo() << "Creating IconItemDelegate";
Copy link

Choose a reason for hiding this comment

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

nitpick: Info-level log in constructor may be too coarse

Frequent delegate construction may clutter info logs; consider using fmDebug() for less verbosity.

@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 17, 2025

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit 3702b1f into linuxdeepin:master Jun 17, 2025
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