Skip to content

Crash Reports API - #103

Open
SpaceWalkerRS wants to merge 5 commits into
gen2from
module/crash-reports
Open

SpaceWalkerRS wants to merge 5 commits into
gen2from
module/crash-reports

Conversation

@SpaceWalkerRS

Copy link
Copy Markdown
Member
  • Adds mods list to crash reports.
  • Improves crash reports in 12w15a-1.4.2 and implements modern crash report system in 1.2.5 and below, including saving crash reports to disk.
  • Adds API for adding details to Vanilla crash report sections.
  • Adds version-independent API for throwing crash exceptions.

Throwing Crash Exceptions

The CrashExceptions utility class provides a few methods for creating crash exceptions.

CrashExceptions {

	// creates a crash report from the given error and title and returns a new crash exception with that report
	CrashException from(String title, Throwable error);

	// creates a new crash report from the given error and title, then passing it to the given builder to populate it,
	// and returns a new crash exception with that report
	CrashException from(String title, Throwable error, Consumer<CrashReport> builder);

}

example usage:

try {
	cookieMonster.eatCookie(cookie);
} catch (Throwable error) {
	throw CrashExceptions.from("Cookie monster encountered an error while eating a cookie", error, report -> {
		CrashReportSection section = report.addSection("Cookie Monster");

		section.addDetail("Name", () -> cookieMonster.getName());
		section.addDetail("Cookie Recipe", () -> cookie.getRecipe());
	})
}

Populating Crash Reports

Several classes (Minecraft, MinecraftServer, World, WorldData) implement the new CrashReportPopulator interface, which allows modders to add crash listeners to objects of these types. When a crash happens these listeners are notified and given the opportunity to add more details to the given crash report section or add a new section to the crash report.

MinecraftClientEvents.START.register(minecraft -> {
	World world = minecraft.world;

	minecraft.addCrashListener((report, section) -> {
		CrashReportSection section = report.addSection("Cookie Management");
	
		section.addDetail("Cookies made", "Not enough!");
		section.addDetail("Cookies eaten", "All of them!");
	});
	world.addCrashListener((report, section) -> {
		section.addDetail("Cookie monsters", () -> world.cookieMonsters.size());
	});
});

@SpaceWalkerRS SpaceWalkerRS added the enhancement New feature or request label Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant