Skip to content

fix: demote DConfig warnings when meta file is not installed - #588

Open
Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/dde-shell-warning-batch3
Open

Ivy233 wants to merge 1 commit into
linuxdeepin:masterfrom
Ivy233:fix/dde-shell-warning-batch3

Conversation

@Ivy233

@Ivy233 Ivy233 commented Oct 5, 2026 •

Copy link
Copy Markdown

"Can't acquire config manager" and "DConfig is invalid" were printed at warning level in two expected cases: the config resource's meta file is simply not installed on the system (e.g. an optional component's config accessed unconditionally). The daemon replies with a generic org.freedesktop.DBus.Error.Failed for a missing resource, which cannot be distinguished from real failures by error name.

Check the meta path locally with the same lookup logic the daemon uses (DConfigMetaImpl::metaPath via DConfigFile) and demote both messages to debug output when the meta file is missing, keeping the warning level for real backend failures (meta present but the backend could not be created, e.g. dde-dconfig-daemon unavailable).

修复元数据未安装时 DConfig 的告警误报:

配置资源的 meta 文件未安装属预期场景(如可选组件的配置被无条件
读取),此前 "Can't acquire config manager" 与 "DConfig is invalid" 均以 warning 级别打印。daemon 对缺资源返回通用 Failed 错误,无法按
错误名区分。现用与 daemon 同源的 meta 查找(DConfigFile 的
metaPath)在本地判断:meta 未安装降为 qCDebug,meta 在位但后端
创建失败(如 daemon 不可用)保留 qCWarning。

PMS: TASK-394335

Summary by Sourcery

Reduce false-positive DConfig warnings for configuration resources whose meta files are not installed.

Bug Fixes:

  • Demote DConfig warnings to debug output when the configuration resource’s meta file is not installed, while retaining warnings for genuine backend failures.

Enhancements:

  • Use local meta-file lookup to distinguish expected missing resources from unavailable or invalid DConfig backends.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233

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

Details 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

@sourcery-ai

sourcery-ai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR uses DConfigFile's daemon-aligned meta-path lookup to identify uninstalled config resources and demotes the two resulting expected warnings to debug output, while keeping warnings for failures when metadata exists, such as an unavailable or uncreatable backend.

Sequence diagram for DConfig missing-meta diagnostic handling

sequenceDiagram
    participant Client
    participant DConfigPrivate
    participant DConfigFile
    participant Daemon as dde-dconfig-daemon
    participant Logger

    Client->>DConfigPrivate: invalid()
    DConfigPrivate->>Daemon: acquire config manager
    Daemon-->>DConfigPrivate: DBus reply
    alt manager acquisition fails
        DConfigPrivate->>DConfigFile: metaPath()
        DConfigFile-->>DConfigPrivate: empty or present path
        alt meta file not installed
            DConfigPrivate->>Logger: qCDebug(Can't acquire config manager)
        else meta file present
            DConfigPrivate->>Logger: qCWarning(Can't acquire config manager)
        end
    end
    DConfigPrivate->>DConfigFile: metaPath()
    DConfigFile-->>DConfigPrivate: empty or present path
    alt backend invalid and meta missing
        DConfigPrivate->>Logger: qCDebug(DConfig is invalid)
    else backend invalid and meta present
        DConfigPrivate->>Logger: qCWarning(DConfig is invalid)
    end
Loading

File-Level Changes

Change Details Files
Add a local meta-file presence check using the same lookup path as the daemon to classify missing config resources.
  • Introduce DConfigPrivate::metaInstalled() based on DConfigFile and metaPath().
  • Use the check to distinguish absent metadata from backend creation failures.
src/dconfig.cpp
Demote diagnostics for expected missing-resource cases while preserving warnings for actual backend failures.
  • Log invalid DConfig state at debug level when metadata is absent, otherwise retain warning level.
  • Log config-manager acquisition failures at debug level when metadata is absent, otherwise retain warning level.
src/dconfig.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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/dconfig.cpp" line_range="158-165" />
<code_context>

     virtual ~DConfigPrivate() override;

+    // Checks whether the meta file for this config is installed locally,
+    // using the same lookup logic as dde-dconfig-daemon
+    // (DConfigMetaImpl::metaPath). Used to distinguish "config resource
+    // never installed" (expected, debug-level) from real backend failures.
+    bool metaInstalled() const
+    {
+        DConfigFile configFile(appId, name, subpath);
+        return !configFile.meta()->metaPath().isEmpty();
+    }
+
</code_context>
<issue_to_address>
**issue (bug_risk):** When `D_DISABLE_DCONFIG` is defined, `dconfig.cpp` deliberately does not include `dconfigfile.h`, but the new `metaInstalled()` method still instantiates `DConfigFile`; that configuration therefore fails to compile with an unknown type or incomplete declaration.

**Triggers:** When building the supported `D_DISABLE_DCONFIG` configuration.

**Suggested fix:** Guard `metaInstalled()` and its call sites with `#ifndef D_DISABLE_DCONFIG`, or provide an equivalent implementation that does not depend on `DConfigFile` in that configuration.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/dconfig.cpp
"Can't acquire config manager" and "DConfig is invalid" were printed at
warning level in two expected cases: the config resource's meta file is
simply not installed on the system (e.g. an optional component's config
accessed unconditionally). The daemon replies with a generic
org.freedesktop.DBus.Error.Failed for a missing resource, which cannot
be distinguished from real failures by error name.

Check the meta path locally with the same lookup logic the daemon uses
(DConfigMetaImpl::metaPath via DConfigFile) and demote both messages to
debug output when the meta file is missing, keeping the warning level
for real backend failures (meta present but the backend could not be
created, e.g. dde-dconfig-daemon unavailable).

修复元数据未安装时 DConfig 的告警误报:

配置资源的 meta 文件未安装属预期场景(如可选组件的配置被无条件
读取),此前 "Can't acquire config manager" 与 "DConfig is invalid"
均以 warning 级别打印。daemon 对缺资源返回通用 Failed 错误,无法按
错误名区分。现用与 daemon 同源的 meta 查找(DConfigFile 的
metaPath)在本地判断:meta 未安装降为 qCDebug,meta 在位但后端
创建失败(如 daemon 不可用)保留 qCWarning。

PMS: TASK-394335
@Ivy233
Ivy233 force-pushed the fix/dde-shell-warning-batch3 branch from 1c6db18 to 47db64e Compare October 5, 2026 14:27
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 97 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 97 分,大于 70 分通过阈值,代码质量符合要求。本次变更目的是降低 DConfig 元数据未安装时的告警级别,实现逻辑正确,注释完善,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 语法正确,逻辑清晰,无需修改


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: 代码结构清晰,注释完整,无需修改


3. 代码性能 ✅

评价: 良好 ✅ 通过

潜在问题:

  1. src/dconfig.cpp:163 - metaInstalled() 每次调用都创建 DConfigFile 对象并执行文件系统查找,无缓存,在错误路径频繁调用时存在性能开销

建议: 建议缓存 metaInstalled() 的结果(如在 DConfigPrivate 中添加 mutable bool metaCached 和 bool metaInstalledResult 成员),避免在错误路径中重复创建 DConfigFile 和执行文件系统查找


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 存在 0 个安全漏洞
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个

安全漏洞详情:
✅ 未发现安全漏洞

建议: 无安全风险,安全合规


💡 改进建议代码示例

// 建议在 DConfigPrivate 中缓存 metaInstalled() 结果
#ifndef D_DISABLE_DCONFIG
    mutable bool metaCached = false;
    mutable bool metaInstalledResult = false;

    bool metaInstalled() const
    {
        if (!metaCached) {
            DConfigFile configFile(appId, name, subpath);
            metaInstalledResult = !configFile.meta()->metaPath().isEmpty();
            metaCached = true;
        }
        return metaInstalledResult;
    }
#endif

本报告由 AI 代码审查工具自动生成

This branch has not been deployed

No deployments
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.

2 participants