Skip to content

Commit

Permalink
Add extensible crash report header system (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt authored Feb 12, 2024
1 parent 6277474 commit 9b239e3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 16 additions & 0 deletions loader/src/main/java/net/neoforged/fml/CrashReportCallables.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class CrashReportCallables
{
private static final Logger LOGGER = LogUtils.getLogger();
private static final List<ISystemReportExtender> crashCallables = Collections.synchronizedList(new ArrayList<>());
private static final List<ICrashReportHeader> HEADERS = Collections.synchronizedList(new ArrayList<>());

/**
* Register a custom {@link ISystemReportExtender}
Expand Down Expand Up @@ -90,8 +93,21 @@ public boolean isActive()
});
}

/**
* Registers a header to be added to the top of crash reports.
*
* @param header the header
*/
public static void registerHeader(ICrashReportHeader header) {
HEADERS.add(header);
}

public static List<ISystemReportExtender> allCrashCallables()
{
return List.copyOf(crashCallables);
}

public static Stream<String> getHeaders() {
return HEADERS.stream().map(ICrashReportHeader::getHeader).filter(Objects::nonNull);
}
}
21 changes: 21 additions & 0 deletions loader/src/main/java/net/neoforged/fml/ICrashReportHeader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.fml;

import org.jetbrains.annotations.Nullable;

/**
* Supplies a header to add to crash reports.
* @see CrashReportCallables#registerHeader(ICrashReportHeader)
*/
@FunctionalInterface
public interface ICrashReportHeader {
/**
* {@return the header to be displayed at the top of the crash report, or {@code null} if the header shouldn't be added}
*/
@Nullable
String getHeader();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@

package net.neoforged.fml;

import org.jetbrains.annotations.ApiStatus;

import java.util.function.Supplier;

@ApiStatus.OverrideOnly
public interface ISystemReportExtender extends Supplier<String>
{
String getLabel();

default boolean isActive()
{
default boolean isActive() {
return true;
}
}

0 comments on commit 9b239e3

Please sign in to comment.