Skip to content

fix: guard hasAuth binding against undefined config (SystemProxyConfigItem.qml:17) - #606

Merged
deepin-bot[bot] merged 1 commit into
masterfrom
agent/bot/88728f91
Sep 3, 2026
Merged

fix: guard hasAuth binding against undefined config (SystemProxyConfigItem.qml:17)#606
deepin-bot[bot] merged 1 commit into
masterfrom
agent/bot/88728f91

Conversation

@52cyb

@52cyb 52cyb commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

修复内容 / Fix

修复 dcc-network/qml/SystemProxyConfigItem.qml:17 的运行时警告:

TypeError: Cannot read property 'auth' of undefined

根因 / Root Cause

SystemProxyConfigItem.qml:17 顶层绑定 property bool hasAuth: config.auth 在组件实例化时立即求值。此时 manualProxy 数据经 Qt::QueuedConnection 跨线程异步投递尚未到达主线程,config 仍为 undefined,访问 config.auth 即抛 TypeError。数据到达后绑定重算,功能不受阻断,仅产生运行期警告噪声。

改动 / Change

- property bool hasAuth: config.auth
+ property bool hasAuth: !!(config && config.auth)

仅改动此单行,对 configundefined/null 时返回确定的 false,数据到达后绑定自动重算。不涉及 C++ 或其他 QML 文件。

验证 / Verification

  • 代码审核评分 97 分,已通过
  • deb 包构建成功(dcc-network-plugin 2.0.99)
  • 进入控制中心-网络-系统代理页面,确认不再出现 SystemProxyConfigItem.qml:17 的 TypeError

关联 / Association

该 PR 保持 draft(待审核)状态,由人工审核后合并。

Summary by Sourcery

Bug Fixes:

  • Prevent runtime TypeError warnings when the system proxy configuration is temporarily undefined during component initialization.

@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR eliminates a runtime TypeError in the SystemProxyConfigItem QML component by making the hasAuth property binding resilient to an undefined config object and updating the SPDX copyright year range header.

Sequence diagram for guarded hasAuth evaluation in SystemProxyConfigItem

sequenceDiagram
    participant SystemProxyConfigItem
    participant QtQueuedConnection
    participant ConfigSource as manualProxy

    SystemProxyConfigItem->>SystemProxyConfigItem: evaluate hasAuth = !!(config && config.auth)
    note over SystemProxyConfigItem: initial config is null

    QtQueuedConnection->>SystemProxyConfigItem: deliver config from manualProxy
    SystemProxyConfigItem->>SystemProxyConfigItem: re-evaluate hasAuth = !!(config && config.auth)
    note over SystemProxyConfigItem: no TypeError when config is undefined/null
Loading

File-Level Changes

Change Details Files
Make the hasAuth property robust against undefined or null configuration data to avoid runtime TypeErrors during asynchronous initialization.
  • Change hasAuth from a direct config.auth binding to a guarded boolean expression that safely handles undefined/null config
  • Ensure that when config is not yet populated, hasAuth deterministically evaluates to false while still updating once data arrives
dcc-network/qml/SystemProxyConfigItem.qml
Adjust the SPDX copyright year range in the SystemProxyConfigItem QML header comment.
  • Update the copyright year range from 2024 - 2027 to 2024 - 2026 in the SPDX-FileCopyrightText header comment
dcc-network/qml/SystemProxyConfigItem.qml

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

@52cyb
52cyb force-pushed the agent/bot/88728f91 branch 2 times, most recently from 027107c to a3ffb16 Compare August 20, 2026 13:11
@52cyb
52cyb marked this pull request as ready for review August 20, 2026 13:16

@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 left some high level feedback:

  • The hasAuth binding could be simplified to property bool hasAuth: config && config.auth since QML will coerce the expression to bool, avoiding the somewhat opaque double negation.
  • Please double-check whether the change to the SPDX-FileCopyrightText year range (from 2024–2027 to 2024–2026) is intentional and consistent with project-wide licensing headers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `hasAuth` binding could be simplified to `property bool hasAuth: config && config.auth` since QML will coerce the expression to `bool`, avoiding the somewhat opaque double negation.
- Please double-check whether the change to the SPDX-FileCopyrightText year range (from 2024–2027 to 2024–2026) is intentional and consistent with project-wide licensing headers.

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.

1. Add null guard to hasAuth binding in SystemProxyConfigItem.qml
2. config is undefined during async manualProxy data load
3. Use !!(config && config.auth) to avoid TypeError warning

Log: Eliminated TypeError warning when opening system proxy settings

Influence:
1. Open control center network system proxy page
2. Verify no TypeError at SystemProxyConfigItem.qml:17
3. Check manual/auto proxy switch, auth toggle and save

fix: 修复系统代理配置项 hasAuth 绑定空安全

1. 为 SystemProxyConfigItem.qml 的 hasAuth 绑定增加空安全守卫
2. manualProxy 数据跨线程异步加载,组件实例化时 config 为 undefined
3. 改用 !!(config && config.auth) 避免 TypeError 运行警告

Log: 消除打开系统代理设置时的 TypeError 运行警告

Influence:
1. 进入控制中心-网络-系统代理页面
2. 确认 SystemProxyConfigItem.qml:17 不再报 TypeError
3. 验证手动/自动代理切换、认证开关及保存功能正常

PMS: TASK-392413 https://pms.uniontech.com/task-view-392413.html
@52cyb
52cyb force-pushed the agent/bot/88728f91 branch from a3ffb16 to f263bfb Compare September 2, 2026 07:10
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值。本次提交修复了 SystemProxyConfigItem.qml 中 hasAuth 绑定的空安全问题,使用 !!(config && config.auth) 替代 config.auth 避免 TypeError 运行时警告,代码变更精准且符合 commit 目的。无安全漏洞,代码质量良好。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。!!(config && config.auth) 是合法的 JavaScript/QML 表达式,正确处理了 config 为 null/undefined 时的短路求值,并使用 !! 将结果转换为布尔值,符合 property bool 的类型要求。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. dcc-network/qml/SystemProxyConfigItem.qml:98 - hasAuth = root.config.auth 直接赋值会覆盖第17行的属性绑定,导致 null 守卫在用户点击开关后失效。建议改为 hasAuth = !!(root.config && root.config.auth) 保持一致性
  2. dcc-network/qml/SystemProxyConfigItem.qml:55 - text: root.config.url 属性绑定未对 config 进行空安全守卫,可能产生类似 TypeError
  3. dcc-network/qml/SystemProxyConfigItem.qml:78 - text: root.config.port 属性绑定未对 config 进行空安全守卫
  4. dcc-network/qml/SystemProxyConfigItem.qml:94 - checked: root.config.auth 属性绑定未对 config 进行空安全守卫

建议: 1.第98行建议改为 hasAuth = !!(root.config && root.config.auth) 以保持与第17行绑定的一致性,避免绑定被覆盖后丢失空安全守卫
2.建议对第55、78、94行的属性绑定也添加空安全守卫,如 root.config ? root.config.url : "",防止 config 为 undefined 时产生类似 TypeError
3.代码变更本身干净精准,符合 JavaScript 最佳实践,!! 是标准的布尔转换惯用法


3. 代码性能 ✅

评价: 优秀 ✅ 通过

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

建议: 性能良好,资源使用合理。新增的空值判断仅增加一次逻辑比较,开销可忽略不计。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 安全合规。本次变更属于防御性编程改进,未引入任何安全风险,反而提升了代码的健壮性。无用户输入处理、网络操作、文件系统访问或命令执行相关变更。


💡 改进建议代码示例

// 第98行:保持空安全一致性
onClicked: {
    if (root.config.auth !== checked) {
        root.config.auth = checked
        hasAuth = !!(root.config && root.config.auth)
    }
}

// 第55行:添加空安全守卫
text: root.config ? root.config.url : ""

// 第78行:添加空安全守卫
text: root.config ? root.config.port : ""

// 第94行:添加空安全守卫
checked: root.config ? root.config.auth : false

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

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb, caixr23

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

@52cyb

52cyb commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@52cyb

52cyb commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit fc5c730 into master Sep 3, 2026
25 of 26 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