Skip to content

refactor(crash): 直接从启动器内 API 获取部分环境信息#3080

Closed
LuLu-ling wants to merge 0 commit into
refactor/crashfrom
refactor/crash-l
Closed

refactor(crash): 直接从启动器内 API 获取部分环境信息#3080
LuLu-ling wants to merge 0 commit into
refactor/crashfrom
refactor/crash-l

Conversation

@LuLu-ling

@LuLu-ling LuLu-ling commented Jun 8, 2026

Copy link
Copy Markdown
Member

解决从启动器日志读取信息可能读到过时值的问题

Summary by Sourcery

优化崩溃分析运行时上下文,从启动器的运行时状态直接读取 Java、账号和内存信息,而不是解析启动器日志,并引入一种新的崩溃日志类型,用于表示由启动器提供的数据。

Enhancements:

  • 使用启动器运行时 API 填充崩溃运行时上下文中的 Java 详情、已分配内存以及账号/认证信息,而不是从日志文件中读取。
  • 移除已废弃的启动日志解析助手,并更新崩溃事实解析器,使其将相关事实归因到新的启动器崩溃日志类型。
Original summary in English

Summary by Sourcery

Refine crash analysis runtime context to read Java, account, and memory information directly from launcher runtime state instead of parsing launcher logs, and introduce a new crash log kind to represent launcher-provided data.

Enhancements:

  • Use launcher runtime API to populate Java details, allocated memory, and account/auth information in crash runtime context instead of reading from log files.
  • Remove obsolete launch log parsing helper and update crash fact parsers to attribute facts to the new launcher crash log kind.

@LuLu-ling LuLu-ling requested a review from Chiloven945 June 8, 2026 09:18
@pcl-ce-automation pcl-ce-automation Bot added 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 size: M PR 大小评估:中型 labels Jun 8, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 8, 2026

Copy link
Copy Markdown
审阅者指南(在小型 PR 上折叠)

审阅者指南

重构崩溃运行时上下文的收集方式,从启动器状态中直接获取 Java、内存和账号信息,而不是解析启动器日志;同时为来自启动器的元数据引入新的 CrashLogKind,并更新解析器以使用该类型。

更新后的崩溃运行时上下文创建时序图

sequenceDiagram
    participant MinecraftCrashController
    participant PageInstanceSetup
    participant ModLaunch
    participant mcLaunchJavaSelected
    participant mcLoginLoader

    MinecraftCrashController->>MinecraftCrashController: AnalyzeGameCrash(request)
    MinecraftCrashController->>MinecraftCrashController: _Create(instance, launchScript)
    MinecraftCrashController->>PageInstanceSetup: GetRam(instance)
    PageInstanceSetup-->>MinecraftCrashController: ram

    MinecraftCrashController->>ModLaunch: mcLaunchJavaSelected
    ModLaunch-->>MinecraftCrashController: mcLaunchJavaSelected
    MinecraftCrashController->>mcLaunchJavaSelected: Installation
    mcLaunchJavaSelected-->>MinecraftCrashController: Installation.ToString()
    mcLaunchJavaSelected-->>MinecraftCrashController: Installation.JavaFolder

    MinecraftCrashController->>ModLaunch: mcLoginLoader
    ModLaunch-->>MinecraftCrashController: mcLoginLoader
    MinecraftCrashController->>mcLoginLoader: output
    mcLoginLoader-->>MinecraftCrashController: output.Name, output.Type

    MinecraftCrashController->>MinecraftCrashController: new CrashRuntimeContext
    Note over MinecraftCrashController: CrashRuntimeContext 现在使用启动器状态
Loading

文件级变更

变更 详情 文件
直接通过启动器 API 收集崩溃运行时的 Java、内存和账号元数据,而不是从日志文件中读取。
  • 通过 PageInstanceSetup.GetRam 获取 RAM,并在崩溃上下文中以 GB 和 MB 两种格式表示已分配内存。
  • 用 ModLaunch.mcLaunchJavaSelected.Installation 中的值替换从日志中解析的 JavaInfo/JavaPath。
  • 用 ModLaunch.mcLoginLoader.output 中的值替换从日志中解析的账号名称和认证类型。
  • 从 MinecraftCrashController 中移除 _ReadLaunchLogValue 辅助方法及其相关日志依赖。
Plain Craft Launcher 2/Modules/Minecraft/Crash/MinecraftCrashController.cs
为启动器运行时数据引入独立的 CrashLogKind,并更新解析器以将事实归因到该类型。
  • 在 CrashLogKind 中添加 Launcher 枚举成员,用于表示启动器提供的运行时上下文。
  • 更新 JavaCrashParser,将与 Java 相关的事实标记为来自 CrashLogKind.Launcher,而不是 CrashLogKind.LauncherLog。
  • 更新 MinecraftCrashReportParser,将 MinecraftVersion 相关事实标记为来自 CrashLogKind.Launcher,而不是 CrashLogKind.LauncherLog。
PCL.Core/Minecraft/CrashAnalysis/Input/CrashLogKind.cs
PCL.Core/Minecraft/CrashAnalysis/Parsing/Parsers/JavaCrashParser.cs
PCL.Core/Minecraft/CrashAnalysis/Parsing/Parsers/MinecraftCrashReportParser.cs

提示与命令

与 Sourcery 交互

  • 触发新的审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 通过回复某条审阅评论,让 Sourcery 从该评论创建 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来创建对应的 issue。
  • 生成 pull request 标题: 在 pull request 标题任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request body 任意位置写入 @sourcery-ai summary,即可在指定位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任何时候(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,以解决所有 Sourcery 评论。当你已经处理完所有评论且不希望再看到它们时非常有用。
  • 忽略所有 Sourcery 审阅: 在 pull request 中评论 @sourcery-ai dismiss,以忽略所有已有的 Sourcery 审阅。特别适用于你希望从头开始一次新的审阅时——别忘了再评论 @sourcery-ai review 来触发新的审阅!

自定义你的体验

访问你的 dashboard 以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors crash runtime context collection to pull Java, memory, and account information directly from launcher state instead of parsing launcher logs, and introduces a new CrashLogKind for launcher-derived metadata while updating parsers to use it.

Sequence diagram for updated crash runtime context creation

sequenceDiagram
    participant MinecraftCrashController
    participant PageInstanceSetup
    participant ModLaunch
    participant mcLaunchJavaSelected
    participant mcLoginLoader

    MinecraftCrashController->>MinecraftCrashController: AnalyzeGameCrash(request)
    MinecraftCrashController->>MinecraftCrashController: _Create(instance, launchScript)
    MinecraftCrashController->>PageInstanceSetup: GetRam(instance)
    PageInstanceSetup-->>MinecraftCrashController: ram

    MinecraftCrashController->>ModLaunch: mcLaunchJavaSelected
    ModLaunch-->>MinecraftCrashController: mcLaunchJavaSelected
    MinecraftCrashController->>mcLaunchJavaSelected: Installation
    mcLaunchJavaSelected-->>MinecraftCrashController: Installation.ToString()
    mcLaunchJavaSelected-->>MinecraftCrashController: Installation.JavaFolder

    MinecraftCrashController->>ModLaunch: mcLoginLoader
    ModLaunch-->>MinecraftCrashController: mcLoginLoader
    MinecraftCrashController->>mcLoginLoader: output
    mcLoginLoader-->>MinecraftCrashController: output.Name, output.Type

    MinecraftCrashController->>MinecraftCrashController: new CrashRuntimeContext
    Note over MinecraftCrashController: CrashRuntimeContext now uses launcher state
Loading

File-Level Changes

Change Details Files
Collect crash runtime Java, memory, and account metadata directly from launcher APIs instead of reading from log files.
  • Add RAM retrieval via PageInstanceSetup.GetRam and format allocated memory as both GB and MB for crash context.
  • Replace log-derived JavaInfo/JavaPath with values from ModLaunch.mcLaunchJavaSelected.Installation.
  • Replace log-derived account name and auth type with values from ModLaunch.mcLoginLoader.output.
  • Remove the _ReadLaunchLogValue helper and associated logging dependency from MinecraftCrashController.
Plain Craft Launcher 2/Modules/Minecraft/Crash/MinecraftCrashController.cs
Introduce a distinct CrashLogKind for launcher runtime data and update parsers to attribute facts to it.
  • Add Launcher enum member to CrashLogKind to represent launcher-provided runtime context.
  • Update JavaCrashParser to mark Java-related facts as coming from CrashLogKind.Launcher instead of CrashLogKind.LauncherLog.
  • Update MinecraftCrashReportParser to mark MinecraftVersion facts as coming from CrashLogKind.Launcher instead of CrashLogKind.LauncherLog.
PCL.Core/Minecraft/CrashAnalysis/Input/CrashLogKind.cs
PCL.Core/Minecraft/CrashAnalysis/Parsing/Parsers/JavaCrashParser.cs
PCL.Core/Minecraft/CrashAnalysis/Parsing/Parsers/MinecraftCrashReportParser.cs

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

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b00794438e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread Plain Craft Launcher 2/Modules/Minecraft/Crash/MinecraftCrashController.cs Outdated

@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 - 我在这里给出了一些高层面的反馈:

  • _Create 中不对 ModLaunch.mcLaunchJavaSelected.InstallationModLaunch.mcLoginLoader.output 进行空值检查就直接访问,会在崩溃上下文在非正常启动流程之外构建时带来空引用崩溃的风险;建议为这些访问加上保护,或者提供合理的备用处理。
  • CrashLogKind 枚举中间添加 Launcher 会改变后续成员(例如 EnvironmentSnapshotImportedText)的数值;如果这些数值会被持久化或跨边界使用,建议将新成员追加到末尾,或者为枚举显式指定数值以保持兼容性。
供 AI 代理使用的提示
Please address the comments from this code review:

## Overall Comments
- Accessing `ModLaunch.mcLaunchJavaSelected.Installation` and `ModLaunch.mcLoginLoader.output` without null checks in `_Create` risks null reference crashes when the crash context is built outside a normal launch flow; consider guarding these accesses or providing sensible fallbacks.
- Adding `Launcher` in the middle of the `CrashLogKind` enum shifts the numeric values of subsequent members (e.g., `EnvironmentSnapshot`, `ImportedText`); if these values are persisted or used across boundaries, consider appending the new member at the end or assigning explicit values to preserve compatibility.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进评审质量。
Original comment in English

Hey - I've left some high level feedback:

  • Accessing ModLaunch.mcLaunchJavaSelected.Installation and ModLaunch.mcLoginLoader.output without null checks in _Create risks null reference crashes when the crash context is built outside a normal launch flow; consider guarding these accesses or providing sensible fallbacks.
  • Adding Launcher in the middle of the CrashLogKind enum shifts the numeric values of subsequent members (e.g., EnvironmentSnapshot, ImportedText); if these values are persisted or used across boundaries, consider appending the new member at the end or assigning explicit values to preserve compatibility.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Accessing `ModLaunch.mcLaunchJavaSelected.Installation` and `ModLaunch.mcLoginLoader.output` without null checks in `_Create` risks null reference crashes when the crash context is built outside a normal launch flow; consider guarding these accesses or providing sensible fallbacks.
- Adding `Launcher` in the middle of the `CrashLogKind` enum shifts the numeric values of subsequent members (e.g., `EnvironmentSnapshot`, `ImportedText`); if these values are persisted or used across boundaries, consider appending the new member at the end or assigning explicit values to preserve compatibility.

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.

@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 and removed 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 labels Jun 8, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48f16fd737

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +62 to +66
JavaInfo = ModLaunch.mcLaunchJavaSelected.Installation.ToString(),
JavaPath = ModLaunch.mcLaunchJavaSelected.Installation.JavaFolder,
AllocatedMemory = $"{ram.ToString("N1", CultureInfo.InvariantCulture)} GB({(ram * 1024d).ToString("N0", CultureInfo.InvariantCulture)} MB)",
AccountName = ModLaunch.mcLoginLoader.output.Name,
AuthType = ModLaunch.mcLoginLoader.output.Type,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Capture the crashed launch context instead of globals

When another game launch starts before this crash-analysis thread runs (the watcher waits 2 seconds before calling AnalyzeGameCrash), these fields are read from the mutable ModLaunch.mcLaunchJavaSelected and mcLoginLoader.output singletons rather than from the launch that just crashed. Since those globals are reassigned during each launch, the report can attribute the crashed instance to the next launch's Java path/version or account, causing environment facts and diagnoses to be wrong; pass the selected Java/login data in MinecraftCrashUiRequest at launch/watch creation time instead.

Useful? React with 👍 / 👎.

@LuLu-ling LuLu-ling closed this Jun 8, 2026
@pcl-ce-automation pcl-ce-automation Bot added 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查 size: XS PR 大小评估:微型 and removed 🕑 等待合并 已处理完毕,正在等待代码合并入主分支 size: M PR 大小评估:中型 labels Jun 8, 2026
@Chiloven945 Chiloven945 deleted the refactor/crash-l branch June 15, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XS PR 大小评估:微型 🛠️ 等待审查 Pull Request 已完善,等待维护者或负责人进行代码审查

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant