Search in sources :

Example 1 with CrashReportCategory

use of net.minecraft.CrashReportCategory in project MinecraftForge by MinecraftForge.

the class CrashReportExtender method dumpModLoadingCrashReport.

public static File dumpModLoadingCrashReport(final Logger logger, final LoadingFailedException error, final File topLevelDir) {
    final CrashReport crashReport = CrashReport.forThrowable(new Exception("Mod Loading has failed"), "Mod loading error has occurred");
    error.getErrors().forEach(mle -> {
        final Optional<IModInfo> modInfo = Optional.ofNullable(mle.getModInfo());
        final CrashReportCategory category = crashReport.addCategory(modInfo.map(iModInfo -> "MOD " + iModInfo.getModId()).orElse("NO MOD INFO AVAILABLE"));
        Throwable cause = mle.getCause();
        int depth = 0;
        while (cause != null && cause.getCause() != null && cause.getCause() != cause) {
            category.setDetail("Caused by " + (depth++), cause + generateEnhancedStackTrace(cause.getStackTrace()).replaceAll(Strings.LINE_SEPARATOR + "\t", "\n\t\t"));
            cause = cause.getCause();
        }
        if (cause != null)
            category.applyStackTrace(cause);
        category.setDetail("Mod File", () -> modInfo.map(IModInfo::getOwningFile).map(t -> t.getFile().getFileName()).orElse("NO FILE INFO"));
        category.setDetail("Failure message", () -> mle.getCleanMessage().replace("\n", "\n\t\t"));
        category.setDetail("Mod Version", () -> modInfo.map(IModInfo::getVersion).map(Object::toString).orElse("NO MOD INFO AVAILABLE"));
        category.setDetail("Mod Issue URL", () -> modInfo.map(IModInfo::getOwningFile).map(IModFileInfo.class::cast).flatMap(mfi -> mfi.getConfig().<String>getConfigElement("issueTrackerURL")).orElse("NOT PROVIDED"));
        category.setDetail("Exception message", Objects.toString(cause, "MISSING EXCEPTION MESSAGE"));
    });
    final File file1 = new File(topLevelDir, "crash-reports");
    final File file2 = new File(file1, "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-fml.txt");
    if (crashReport.saveToFile(file2)) {
        logger.fatal("Crash report saved to {}", file2);
    } else {
        logger.fatal("Failed to save crash report");
    }
    System.out.print(crashReport.getFriendlyReport());
    return file2;
}
Also used : IModInfo(net.minecraftforge.forgespi.language.IModInfo) CrashReport(net.minecraft.CrashReport) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) LoadingFailedException(net.minecraftforge.fml.LoadingFailedException) CrashReportCategory(net.minecraft.CrashReportCategory)

Aggregations

File (java.io.File)1 SimpleDateFormat (java.text.SimpleDateFormat)1 CrashReport (net.minecraft.CrashReport)1 CrashReportCategory (net.minecraft.CrashReportCategory)1 LoadingFailedException (net.minecraftforge.fml.LoadingFailedException)1 IModInfo (net.minecraftforge.forgespi.language.IModInfo)1