|
1 | | -package dev.isxander.debugify.mixinplugin; |
| 1 | +package dev.isxander.debugify.error; |
2 | 2 |
|
3 | 3 | import dev.isxander.debugify.Debugify; |
4 | 4 | import dev.isxander.debugify.fixes.BugFixData; |
5 | | -import org.objectweb.asm.tree.ClassNode; |
| 5 | +import dev.isxander.debugify.mixinplugin.BugFixDataCache; |
6 | 6 | import org.spongepowered.asm.mixin.extensibility.IMixinConfig; |
7 | 7 | import org.spongepowered.asm.mixin.extensibility.IMixinErrorHandler; |
8 | 8 | import org.spongepowered.asm.mixin.extensibility.IMixinInfo; |
9 | | -import org.spongepowered.asm.service.MixinService; |
10 | 9 |
|
11 | | -import java.io.IOException; |
| 10 | +import java.util.Collections; |
12 | 11 | import java.util.HashSet; |
13 | 12 | import java.util.Optional; |
14 | 13 | import java.util.Set; |
15 | 14 |
|
16 | 15 | public class DebugifyErrorHandler implements IMixinErrorHandler { |
17 | | - private static final Set<BugFixData> ERRORED_FIXES = new HashSet<>(); |
| 16 | + private static final Set<MixinErrorEntry> ERRORED_FIXES = new HashSet<>(); |
18 | 17 |
|
19 | 18 | @Override |
20 | 19 | public ErrorAction onPrepareError(IMixinConfig config, Throwable th, IMixinInfo mixin, ErrorAction action) { |
21 | | - return handleError(action, mixin); |
| 20 | + return handleError(action, mixin, th, ErrorStage.PREPARE); |
22 | 21 | } |
23 | 22 |
|
24 | 23 | @Override |
25 | 24 | public ErrorAction onApplyError(String targetClassName, Throwable th, IMixinInfo mixin, ErrorAction action) { |
26 | | - return handleError(action, mixin); |
| 25 | + return handleError(action, mixin, th, ErrorStage.APPLY); |
27 | 26 | } |
28 | 27 |
|
29 | | - private ErrorAction handleError(ErrorAction usualAction, IMixinInfo mixin) { |
| 28 | + private ErrorAction handleError(ErrorAction usualAction, IMixinInfo mixin, Throwable th, ErrorStage stage) { |
30 | 29 | Optional<BugFixData> bugFix = BugFixDataCache.getIfResolved(mixin.getClassName()); |
31 | 30 | if (bugFix.isEmpty()) |
32 | 31 | return usualAction; |
33 | 32 |
|
34 | 33 | BugFixData fix = bugFix.get(); |
35 | | - ERRORED_FIXES.add(fix); |
| 34 | + ERRORED_FIXES.add(new MixinErrorEntry(fix, mixin, th, stage)); |
36 | 35 |
|
37 | 36 | // no need to add exception here, it's already logged under ErrorAction.WARN |
38 | 37 | Debugify.LOGGER.error("Failed to fully apply bug fix {}, mixin class {} will not be applied! This may cause runtime errors if a partial injection occurs.", fix.bugId(), mixin.getName()); |
39 | 38 | return ErrorAction.WARN; |
40 | 39 | } |
41 | 40 |
|
42 | 41 | public static boolean hasErrored(BugFixData fix) { |
43 | | - return ERRORED_FIXES.contains(fix); |
| 42 | + return ERRORED_FIXES.stream().anyMatch(entry -> entry.fix().equals(fix)); |
44 | 43 | } |
| 44 | + |
| 45 | + public static Set<MixinErrorEntry> getErroredFixes() { |
| 46 | + return Collections.unmodifiableSet(ERRORED_FIXES); |
| 47 | + } |
| 48 | + |
45 | 49 | } |
0 commit comments