make the error handler a single instance and always dump the displaycontainer
This commit is contained in:
parent
24c6c7da77
commit
4f10577321
|
@ -76,7 +76,7 @@ public class OpsuDance {
|
||||||
try {
|
try {
|
||||||
container.setup();
|
container.setup();
|
||||||
} catch (LWJGLException e) {
|
} catch (LWJGLException e) {
|
||||||
ErrorHandler.error("could not initialize GL", e, container).preventContinue().show();
|
ErrorHandler.error("could not initialize GL", e).preventContinue().show();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
Exception caughtException = null;
|
Exception caughtException = null;
|
||||||
|
@ -86,7 +86,7 @@ public class OpsuDance {
|
||||||
caughtException = e;
|
caughtException = e;
|
||||||
}
|
}
|
||||||
container.teardown();
|
container.teardown();
|
||||||
return caughtException != null && ErrorHandler.error("update/render error", caughtException, container).show().shouldIgnoreAndContinue();
|
return caughtException != null && ErrorHandler.error("update/render error", caughtException).show().shouldIgnoreAndContinue();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDatabase() {
|
private void initDatabase() {
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
*/
|
*/
|
||||||
package yugecin.opsudance.errorhandling;
|
package yugecin.opsudance.errorhandling;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import itdelatrisu.opsu.Options;
|
import itdelatrisu.opsu.Options;
|
||||||
import itdelatrisu.opsu.Utils;
|
import itdelatrisu.opsu.Utils;
|
||||||
import org.newdawn.slick.util.Log;
|
import org.newdawn.slick.util.Log;
|
||||||
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
import yugecin.opsudance.utils.MiscUtils;
|
import yugecin.opsudance.utils.MiscUtils;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -39,32 +41,39 @@ import java.net.URLEncoder;
|
||||||
*/
|
*/
|
||||||
public class ErrorHandler {
|
public class ErrorHandler {
|
||||||
|
|
||||||
private final String customMessage;
|
private static ErrorHandler instance;
|
||||||
private final Throwable cause;
|
|
||||||
private final String errorDump;
|
private final DisplayContainer displayContainer;
|
||||||
private final String messageBody;
|
|
||||||
|
private String customMessage;
|
||||||
|
private Throwable cause;
|
||||||
|
private String errorDump;
|
||||||
|
private String messageBody;
|
||||||
|
|
||||||
private boolean preventContinue;
|
private boolean preventContinue;
|
||||||
private boolean preventReport;
|
private boolean preventReport;
|
||||||
private boolean ignoreAndContinue;
|
private boolean ignoreAndContinue;
|
||||||
|
|
||||||
private ErrorHandler(String customMessage, Throwable cause, ErrorDumpable[] errorInfoProviders) {
|
@Inject
|
||||||
|
public ErrorHandler(DisplayContainer displayContainer) {
|
||||||
|
this.displayContainer = displayContainer;
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ErrorHandler init(String customMessage, Throwable cause) {
|
||||||
this.customMessage = customMessage;
|
this.customMessage = customMessage;
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
|
|
||||||
StringWriter dump = new StringWriter();
|
StringWriter dump = new StringWriter();
|
||||||
for (ErrorDumpable infoProvider : errorInfoProviders) {
|
|
||||||
try {
|
try {
|
||||||
infoProvider.writeErrorDump(dump);
|
displayContainer.writeErrorDump(dump);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
dump
|
dump
|
||||||
.append("### ")
|
.append("### ")
|
||||||
.append(e.getClass().getSimpleName())
|
.append(e.getClass().getSimpleName())
|
||||||
.append(" while creating errordump for ")
|
.append(" while creating errordump");
|
||||||
.append(infoProvider.getClass().getSimpleName());
|
|
||||||
e.printStackTrace(new PrintWriter(dump));
|
e.printStackTrace(new PrintWriter(dump));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
errorDump = dump.toString();
|
errorDump = dump.toString();
|
||||||
|
|
||||||
dump = new StringWriter();
|
dump = new StringWriter();
|
||||||
|
@ -76,10 +85,11 @@ public class ErrorHandler {
|
||||||
Log.error("====== start unhandled exception dump");
|
Log.error("====== start unhandled exception dump");
|
||||||
Log.error(messageBody);
|
Log.error(messageBody);
|
||||||
Log.error("====== end unhandled exception dump");
|
Log.error("====== end unhandled exception dump");
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ErrorHandler error(String message, Throwable cause, ErrorDumpable... errorInfoProviders) {
|
public static ErrorHandler error(String message, Throwable cause) {
|
||||||
return new ErrorHandler(message, cause, errorInfoProviders);
|
return instance.init(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ErrorHandler preventReport() {
|
public ErrorHandler preventReport() {
|
||||||
|
|
|
@ -22,6 +22,7 @@ import yugecin.opsudance.PreStartupInitializer;
|
||||||
import yugecin.opsudance.core.DisplayContainer;
|
import yugecin.opsudance.core.DisplayContainer;
|
||||||
import yugecin.opsudance.core.Demux;
|
import yugecin.opsudance.core.Demux;
|
||||||
import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
|
import yugecin.opsudance.core.state.transitions.EmptyTransitionState;
|
||||||
|
import yugecin.opsudance.errorhandling.ErrorHandler;
|
||||||
import yugecin.opsudance.states.EmptyRedState;
|
import yugecin.opsudance.states.EmptyRedState;
|
||||||
import yugecin.opsudance.states.EmptyState;
|
import yugecin.opsudance.states.EmptyState;
|
||||||
import yugecin.opsudance.core.state.transitions.FadeInTransitionState;
|
import yugecin.opsudance.core.state.transitions.FadeInTransitionState;
|
||||||
|
@ -35,6 +36,8 @@ public class OpsuDanceModule extends AbstractModule {
|
||||||
bind(Demux.class).asEagerSingleton();
|
bind(Demux.class).asEagerSingleton();
|
||||||
bind(DisplayContainer.class).asEagerSingleton();
|
bind(DisplayContainer.class).asEagerSingleton();
|
||||||
|
|
||||||
|
bind(ErrorHandler.class).asEagerSingleton();
|
||||||
|
|
||||||
bind(EmptyTransitionState.class).asEagerSingleton();
|
bind(EmptyTransitionState.class).asEagerSingleton();
|
||||||
bind(FadeInTransitionState.class).asEagerSingleton();
|
bind(FadeInTransitionState.class).asEagerSingleton();
|
||||||
bind(FadeOutTransitionState.class).asEagerSingleton();
|
bind(FadeOutTransitionState.class).asEagerSingleton();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user