Skip to content

fix(backend): tolerate invalid Fabric metadata#1823

Merged
UNIkeEN merged 2 commits into
mainfrom
fix/1764-fabric-metadata
Jul 7, 2026
Merged

fix(backend): tolerate invalid Fabric metadata#1823
UNIkeEN merged 2 commits into
mainfrom
fix/1764-fabric-metadata

Conversation

@pangbo13

@pangbo13 pangbo13 commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Checklist

  • Changes have been tested locally and work as expected.
  • All tests in workflows pass successfully.
  • Documentation has been updated if necessary.
  • Code formatting and commit messages align with the project's conventions.
  • Comments have been added for any complex logic or functionality if possible.

This PR is a ..

  • 🆕 New feature
  • 🐞 Bug fix
  • 🛠 Refactoring
  • ⚡️ Performance improvement
  • 🌐 Internationalization
  • 📄 Documentation improvement
  • 🎨 Code style optimization
  • ❓ Other (Please specify below)

Related Issues

fix #1764

Description

部分fabric模组元数据json未对字符串中\u{0000}~\u{001F}的控制字符转义,导致json解析失败。
修改后,当json解析失败后,尝试从json文件删除上述控制字符重新解析。

Additional Context

  • Add any other relevant information or screenshots here.

Summary by Sourcery

Relax Fabric mod metadata JSON parsing to tolerate invalid control characters in metadata files.

Bug Fixes:

  • Handle Fabric mod metadata files that include unescaped C0 control characters by retrying deserialization after stripping them.

Enhancements:

  • Introduce a reusable lenient JSON deserialization helper that strips control characters and falls back to strict parsing.

@sourcery-ai

sourcery-ai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Centralizes Fabric mod metadata JSON parsing through a new lenient deserialization helper that retries parsing after stripping C0 control characters, and updates Fabric metadata loading from both jars and directories to use this helper.

File-Level Changes

Change Details Files
Use a shared lenient JSON deserializer when reading Fabric mod metadata from jars and directories to tolerate unescaped C0 control characters.
  • Replace direct serde_json parsing of fabric.mod.json from jars with reading into a string and passing through a lenient deserializer.
  • Replace direct serde_json parsing of fabric.mod.json from directories with reading file contents into a string and passing through the same lenient helper.
  • Remove explicit SJMCLError imports now that ? operator is used on SJMCLResult for error propagation.
src-tauri/src/instance/helpers/mods/fabric.rs
Introduce a generic lenient JSON deserialization utility that strips C0 control characters and retries parsing, along with a helper to perform the stripping.
  • Add deserialize_lenient_json that first attempts strict serde_json::from_str and, on failure, retries after sanitizing the input.
  • Implement strip_json_control_chars to remove characters in the \u{0000}-\u{001F} range from JSON text.
  • Import serde::de::DeserializeOwned to support generic JSON deserialization in the new helper.
src-tauri/src/utils/string.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#1764 Allow the launcher to successfully parse and recognize Fabric mods whose fabric.mod.json contains non-standard or invalid JSON due to unescaped C0 control characters (e.g., in the description field), both when reading from JARs and from directories.

Possibly linked issues


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

@github-actions github-actions Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 4, 2026
@pangbo13
pangbo13 requested a review from UNIkeEN July 4, 2026 12:29

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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 thread src-tauri/src/instance/helpers/mods/fabric.rs Outdated
@UNIkeEN

UNIkeEN commented Jul 7, 2026

Copy link
Copy Markdown
Owner

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

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 new deserialize_lenient_json helper silently alters input by stripping all C0 control characters; consider clarifying in the docstring or name that it is intended only for known-bad JSON (e.g., Fabric metadata) and avoid using it more broadly where that data loss might be surprising.
  • strip_json_control_chars currently removes all control characters including newlines and tabs; if you only intend to tolerate invalid characters inside strings, you may want to narrow the filter or add a comment explaining why removing formatting whitespace is acceptable here.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `deserialize_lenient_json` helper silently alters input by stripping all C0 control characters; consider clarifying in the docstring or name that it is intended only for known-bad JSON (e.g., Fabric metadata) and avoid using it more broadly where that data loss might be surprising.
- `strip_json_control_chars` currently removes all control characters including newlines and tabs; if you only intend to tolerate invalid characters inside strings, you may want to narrow the filter or add a comment explaining why removing formatting whitespace is acceptable here.

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.

@UNIkeEN
UNIkeEN merged commit 2a70fb0 into main Jul 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 部分元数据不规范的模组没有识别

2 participants