Skip to content

fix: pass QJsonParseError to QJsonDocument::fromJson in fromJsonString - #1704

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:fix/qjsonparseerror-fromjsonstring
Draft

fix: pass QJsonParseError to QJsonDocument::fromJson in fromJsonString#1704
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:fix/qjsonparseerror-fromjsonstring

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Pass &error to QJsonDocument::fromJson in DPluginMetaData::fromJsonString so the QJsonParseError error branch becomes reachable. Fixes a dead-code defect where malformed JSON was silently swallowed and the qCWarning diagnostic never fired.

Change

  • frame/pluginmetadata.cpp: QJsonDocument::fromJson(data)QJsonDocument::fromJson(data, &error) in fromJsonString.

Behavior

  • Valid JSON: no change.
  • Malformed JSON: now hits the error branch, logs qCWarning with the parse error string, and returns an invalid DPluginMetaData (previously returned invalid via the missing-Id path, silently).

Testing

  • Existing DPluginMetaData.FromJsonStringMalformed unit test still passes — it asserts an invalid result both before and after the fix, so no test update is needed. The previously-unreachable error branch is now reachable for coverage.

Related

Summary by Sourcery

Make JSON parsing errors reachable so malformed plugin metadata is rejected with diagnostic logging.

Bug Fixes:

  • Ensure malformed JSON is reported and rejected with a parse warning in DPluginMetaData::fromJsonString.

Chores:

  • Update the plugin metadata source copyright year range.

@deepin-ci-robot

Copy link
Copy Markdown

Hi @MyLeeJiEun. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Aug 19, 2026

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

Reviewer's Guide

This PR wires QJsonParseError into DPluginMetaData::fromJsonString so JSON parsing failures are correctly detected, logged, and routed through the existing error branch instead of being silently ignored.

Sequence diagram for updated JSON parsing in DPluginMetaData::fromJsonString

sequenceDiagram
    participant Caller
    participant DPluginMetaData
    participant QJsonDocument
    participant Logger

    Caller->>DPluginMetaData: fromJsonString(data)
    activate DPluginMetaData
    DPluginMetaData->>QJsonDocument: fromJson(data, &error)
    QJsonDocument-->>DPluginMetaData: QJsonDocument

    alt [error.error]
        DPluginMetaData->>Logger: qCWarning(dsLog)
        DPluginMetaData-->>Caller: DPluginMetaData()
    else [no parse error]
        DPluginMetaData-->>Caller: DPluginMetaData (from metaData)
    end
    deactivate DPluginMetaData
Loading

File-Level Changes

Change Details Files
Make JSON parse errors in DPluginMetaData::fromJsonString detectable and logged by passing QJsonParseError to QJsonDocument::fromJson.
  • Introduce a local QJsonParseError variable in fromJsonString and pass its address to QJsonDocument::fromJson when creating the QJsonObject.
  • Reuse the existing error handling branch that checks error.error, now correctly triggered on malformed JSON.
  • Preserve existing behavior for valid JSON while improving diagnostics and coverage for malformed JSON inputs.
frame/pluginmetadata.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

1. Pass &error to QJsonDocument::fromJson in fromJsonString
2. Make the QJsonParseError error branch reachable, removing dead code
3. Malformed JSON now triggers qCWarning and returns invalid DPluginMetaData
4. Update SPDX copyright year to 2023 - 2026

Influence:
1. Load plugins with valid JSON metadata, verify normal plugin loading
2. Load a plugin with malformed JSON, verify qCWarning is logged
3. Verify malformed JSON plugin is skipped without crashing the shell

fix: 向 QJsonDocument::fromJson 传入 &error

1. 向 fromJsonString 中的 QJsonDocument::fromJson 传入 &error 出参
2. 使 QJsonParseError 错误分支可达,消除死代码
3. 非法 JSON 现触发 qCWarning 并返回 invalid DPluginMetaData
4. 更新 SPDX 版权年份为 2023 - 2026

Influence:
1. 加载合法 JSON 元数据的插件,验证插件正常加载
2. 加载包含非法 JSON 的插件,验证触发 qCWarning 日志
3. 验证非法 JSON 插件被跳过且不影响 dde-shell 启动

Refs: DDE-132
@MyLeeJiEun
MyLeeJiEun force-pushed the fix/qjsonparseerror-fromjsonstring branch from a51ccc1 to 8970acd Compare August 19, 2026 09:25
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, MyLeeJiEun

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants