Search in sources :

Example 16 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printExceptionSpawningEntity.

static void printExceptionSpawningEntity(final PhaseTracker tracker, final PhaseContext<@NonNull ?> context, final Throwable e) {
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose && !PhasePrinter.printedExceptionsForEntities.isEmpty()) {
        if (PhasePrinter.printedExceptionsForEntities.contains(context.state)) {
            return;
        }
    }
    final PrettyPrinter printer = new PrettyPrinter(60).add("Exception attempting to capture or spawn an Entity!").centre().hr();
    PhasePrinter.printPhasestack(tracker, context, e, printer);
    printer.log(SpongeCommon.logger(), Level.ERROR);
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose) {
        PhasePrinter.printedExceptionsForEntities.add(context.state);
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 17 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printIncorrectPhaseCompletion.

static void printIncorrectPhaseCompletion(final PhaseStack stack, final IPhaseState<@NonNull ?> prevState, final IPhaseState<@NonNull ?> state) {
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose && !PhasePrinter.completedIncorrectStates.isEmpty()) {
        for (final Tuple<IPhaseState<@NonNull ?>, IPhaseState<@NonNull ?>> tuple : PhasePrinter.completedIncorrectStates) {
            if ((tuple.first().equals(prevState) && tuple.second().equals(state))) {
                // being completed incorrectly. only print it once.
                return;
            }
        }
    }
    final PrettyPrinter printer = new PrettyPrinter(60).add("Completing incorrect phase").centre().hr().add("Sponge's tracking system is very dependent on knowing when" + " a change to any world takes place, however, we are attempting" + " to complete a \"phase\" other than the one we most recently entered." + " This is an error usually on Sponge's part, so a report" + " is required on the issue tracker on GitHub.").hr().add("Expected to exit phase: %s", prevState).add("But instead found phase: %s", state).add("StackTrace:").add(new Exception());
    printer.add(" Phases Remaining:");
    PhasePrinter.printPhaseStackWithException(stack, printer, new Exception("Incorrect Phase Completion"));
    if (PhasePrinter.IN_DEVELOPMENT) {
        printer.print(System.err);
    } else {
        printer.log(SpongeCommon.logger(), Level.ERROR);
    }
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose) {
        PhasePrinter.completedIncorrectStates.add(new Tuple<>(prevState, state));
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 18 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printNullSourceForBlock.

static void printNullSourceForBlock(final ServerLevel worldServer, final BlockPos pos, final Block blockIn, final BlockPos otherPos, final NullPointerException e) {
    final PhaseTracker instance = PhaseTracker.getInstance();
    final PrettyPrinter printer = new PrettyPrinter(60).add("Null Source Block from Unknown Source!").centre().hr().addWrapped("Hey, Sponge is saving the game from crashing or spamming because some source " + "put up a \"null\" Block as it's source for sending out a neighbor notification. " + "This is usually unsupported as the game will silently ignore some nulls by " + "performing \"==\" checks instead of calling methods, potentially making an " + "NPE. Because Sponge uses the source block to build information for tracking, " + "Sponge has to save the game from crashing by reporting this issue. Because the " + "source is unknown, it's recommended to report this issue to SpongeCommon's " + "issue tracker on GitHub. Please provide the following information: ").add().add(" %s : %s", "Source position", pos).add(" %s : %s", "World", ((org.spongepowered.api.world.server.ServerWorld) worldServer).key()).add(" %s : %s", "Source Block Recovered", blockIn).add(" %s : %s", "Notified Position", otherPos).add();
    PhasePrinter.printPhaseStackWithException(instance.stack, printer, e);
    printer.log(SpongeCommon.logger(), Level.WARN);
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 19 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printMessageWithCaughtException.

public static void printMessageWithCaughtException(final PhaseStack stack, final String header, final String subHeader, final IPhaseState<@NonNull ?> state, final PhaseContext<@NonNull ?> context, @Nullable final Throwable t) {
    final PrettyPrinter printer = new PrettyPrinter(60);
    printer.add(header).centre().hr().add("%s %s", subHeader, state).addWrapped(60, "%s :", "PhaseContext");
    PhasePrinter.CONTEXT_PRINTER.accept(printer, context);
    printer.addWrapped(60, "%s :", "Phases remaining");
    stack.forEach(data -> PhasePrinter.PHASE_PRINTER.accept(printer, data));
    if (t != null) {
        printer.add("Stacktrace:").add(t);
        if (t.getCause() != null) {
            printer.add(t.getCause());
        }
    }
    printer.add();
    PhasePrinter.generateVersionInfo(printer);
    if (PhasePrinter.IN_DEVELOPMENT) {
        printer.print(System.err);
    } else {
        printer.log(SpongeCommon.logger(), Level.ERROR);
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Example 20 with PrettyPrinter

use of org.spongepowered.common.util.PrettyPrinter in project SpongeCommon by SpongePowered.

the class PhasePrinter method printExceptionFromPhase.

static void printExceptionFromPhase(final PhaseStack stack, final Throwable e, final PhaseContext<@NonNull ?> context) {
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose && !PhasePrinter.printedExceptionsForState.isEmpty()) {
        for (final IPhaseState<@NonNull ?> iPhaseState : PhasePrinter.printedExceptionsForState) {
            if (context.state == iPhaseState) {
                return;
            }
        }
    }
    final PrettyPrinter printer = new PrettyPrinter(60).add("Exception occurred during a PhaseState").centre().hr().add("Sponge's tracking system makes a best effort to not throw exceptions randomly but sometimes it is inevitable. In most " + "cases, something else triggered this exception and Sponge prevented a crash by catching it. The following stacktrace can be " + "used to help pinpoint the cause.").hr().add("The PhaseState having an exception: %s", context.state).add("The PhaseContext:");
    context.printCustom(printer, 4);
    PhasePrinter.printPhaseStackWithException(stack, printer, e);
    if (PhasePrinter.IN_DEVELOPMENT) {
        printer.print(System.err);
    } else {
        printer.log(SpongeCommon.logger(), Level.ERROR);
    }
    if (!SpongeConfigs.getCommon().get().phaseTracker.verbose) {
        PhasePrinter.printedExceptionsForState.add(context.state);
    }
}
Also used : PrettyPrinter(org.spongepowered.common.util.PrettyPrinter)

Aggregations

PrettyPrinter (org.spongepowered.common.util.PrettyPrinter)28 Nullable (org.checkerframework.checker.nullness.qual.Nullable)5 Map (java.util.Map)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 ServerLevel (net.minecraft.server.level.ServerLevel)3 Level (org.apache.logging.log4j.Level)3 PluginContainer (org.spongepowered.plugin.PluginContainer)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Player (net.minecraft.world.entity.player.Player)2 NonNull (org.checkerframework.checker.nullness.qual.NonNull)2