feat: add ability to disable error reporting from command line

Good for local development where it's not needed
This commit is contained in:
Ryan Dowling 2019-07-07 02:23:49 +10:00
parent a6aeec676f
commit 3f4a3c707c
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
3 changed files with 62 additions and 29 deletions

2
.vscode/launch.json vendored
View file

@ -8,7 +8,7 @@
"mainClass": "com.atlauncher.App",
"projectName": "ATLauncher",
"cwd": "${workspaceFolder}/testLauncher",
"args": "--debug --debug-level 3"
"args": "--debug --debug-level 3 --disable-error-reporting"
}
]
}

View file

@ -110,6 +110,14 @@ public class App {
*/
public static boolean skipTrayIntegration = false;
/**
* This allows skipping the in built error reporting. This is mainly useful for
* development when you don't want to report errors to an external third party.
* <p/>
* --disable-error-reporting
*/
public static boolean disableErrorReporting = false;
/**
* This removes writing the launchers location to AppData/Application Support.
* It can be enabled with the below command line argument.
@ -197,9 +205,6 @@ public class App {
// Sets up where all uncaught exceptions go to.
Thread.setDefaultUncaughtExceptionHandler(new ExceptionStrainer());
// Initialize the error reporting
ErrorReporting.init();
}
/**
@ -211,6 +216,9 @@ public class App {
// Parse all the command line arguments
parseCommandLineArguments(args);
// Initialize the error reporting
ErrorReporting.init(disableErrorReporting);
if (Files.notExists(FileSystem.CONFIGS) && FileSystem.CONFIGS.getParent().toFile().listFiles().length > 1) {
String content = HTMLUtils.centerParagraph("I've detected that you may "
+ "not have installed this in the right location.<br/><br/>The exe or jar file should "
@ -542,6 +550,7 @@ public class App {
OptionParser parser = new OptionParser();
parser.accepts("updated").withOptionalArg().ofType(Boolean.class);
parser.accepts("skip-tray-integration").withOptionalArg().ofType(Boolean.class);
parser.accepts("disable-error-reporting").withOptionalArg().ofType(Boolean.class);
parser.accepts("skip-integration").withOptionalArg().ofType(Boolean.class);
parser.accepts("skip-hash-checking").withOptionalArg().ofType(Boolean.class);
parser.accepts("force-offline-mode").withOptionalArg().ofType(Boolean.class);
@ -574,6 +583,11 @@ public class App {
LogManager.debug("Skipping tray integration!", true);
}
disableErrorReporting = options.has("disable-error-reporting");
if (disableErrorReporting) {
LogManager.debug("Disabling error reporting!", true);
}
forceOfflineMode = options.has("force-offline-mode");
if (forceOfflineMode) {
LogManager.debug("Forcing offline mode!", true);

View file

@ -30,28 +30,40 @@ import io.sentry.event.Breadcrumb;
import io.sentry.event.BreadcrumbBuilder;
public final class ErrorReporting {
public static void init() {
SentryClient client = Sentry.init(Constants.SENTRY_DSN);
client.setRelease(Constants.VERSION.toString());
client.addTag("java.version", Java.getLauncherJavaVersion());
public static SentryClient client;
public static void init(boolean enable) {
if (enable) {
client = Sentry.init(Constants.SENTRY_DSN);
client.setRelease(Constants.VERSION.toString());
client.addTag("java.version", Java.getLauncherJavaVersion());
}
}
public static void addExtra(String name, String value) {
Sentry.getContext().addExtra(name, value);
if (client != null) {
client.getContext().addExtra(name, value);
}
}
public static void addTag(String name, String value) {
Sentry.getContext().addTag(name, value);
if (client != null) {
client.getContext().addTag(name, value);
}
}
public static void recordBreadcrumb(String message, Breadcrumb.Type type, Breadcrumb.Level level) {
Sentry.getContext()
.recordBreadcrumb(new BreadcrumbBuilder().setMessage(message).setType(type).setLevel(level).build());
if (client != null) {
client.getContext().recordBreadcrumb(
new BreadcrumbBuilder().setMessage(message).setType(type).setLevel(level).build());
}
}
public static void recordBreadcrumb(Map<String, String> data, Breadcrumb.Type type, Breadcrumb.Level level) {
Sentry.getContext()
.recordBreadcrumb(new BreadcrumbBuilder().setData(data).setType(type).setLevel(level).build());
if (client != null) {
client.getContext()
.recordBreadcrumb(new BreadcrumbBuilder().setData(data).setType(type).setLevel(level).build());
}
}
public static void recordBreadcrumb(String message, Breadcrumb.Level level) {
@ -63,31 +75,38 @@ public final class ErrorReporting {
}
public static void recordNetworkRequest(String url, String timeTaken) {
Map<String, String> data = new HashMap<>();
if (client != null) {
Map<String, String> data = new HashMap<>();
data.put("timeTaken", timeTaken);
data.put("timeTaken", timeTaken);
Sentry.getContext().recordBreadcrumb(new BreadcrumbBuilder().setMessage(url).setType(Breadcrumb.Type.DEFAULT)
.setLevel(Breadcrumb.Level.INFO).setCategory("http.request").setData(data).build());
client.getContext()
.recordBreadcrumb(new BreadcrumbBuilder().setMessage(url).setType(Breadcrumb.Type.DEFAULT)
.setLevel(Breadcrumb.Level.INFO).setCategory("http.request").setData(data).build());
}
}
public static void recordPackInstall(String packName, String packVersion, LoaderVersion loader) {
Map<String, String> data = new HashMap<>();
if (client != null) {
Map<String, String> data = new HashMap<>();
data.put("pack.name", packName);
data.put("pack.version", packVersion);
data.put("pack.name", packName);
data.put("pack.version", packVersion);
if (loader != null) {
data.put("loader.version", loader.version);
data.put("loader.type", loader.type);
if (loader != null) {
data.put("loader.version", loader.version);
data.put("loader.type", loader.type);
}
client.getContext().recordBreadcrumb(
new BreadcrumbBuilder().setMessage("Started pack install").setType(Breadcrumb.Type.USER)
.setLevel(Breadcrumb.Level.INFO).setCategory("pack.install").setData(data).build());
}
Sentry.getContext().recordBreadcrumb(
new BreadcrumbBuilder().setMessage("Started pack install").setType(Breadcrumb.Type.USER)
.setLevel(Breadcrumb.Level.INFO).setCategory("pack.install").setData(data).build());
}
public static void reportError(Throwable t) {
Sentry.capture(t);
if (client != null) {
client.sendException(t);
}
}
}