public final class BugReport extends java.lang.Object implements java.io.Serializable
It allows you to configure the format and request to send the bug report.
It also contains the main entry point for all components to use the bug report system: Call intercept(Throwable)
to start handling an
exception.
You should then add some debug information there. This can be the OSM ids that caused the error, information on the data you were working on or other local variables. Make sure that no exceptions may occur while computing the values. It is best to send plain local variables to put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report. The global exception handler will do the rest.
int id = ...; String tag = "..."; try { ... your code ... } catch (RuntimeException t) { throw BugReport.intercept(t).put("id", id).put("tag", () -> x.getTag()); }Instead of re-throwing, you can call
ReportedException.warn()
. This will display a warning to the user and allow it to either report
the exception or ignore it.Modifier and Type | Class and Description |
---|---|
static interface |
BugReport.BugReportListener
A listener that listens to changes to this report.
|
Modifier and Type | Field and Description |
---|---|
private ReportedException |
exception |
private boolean |
includeAllStackTraces |
private boolean |
includeData |
private boolean |
includeStatusReport |
private java.util.concurrent.CopyOnWriteArrayList<BugReport.BugReportListener> |
listeners |
private static long |
serialVersionUID |
Constructor and Description |
---|
BugReport(ReportedException e)
Create a new bug report
|
Modifier and Type | Method and Description |
---|---|
void |
addChangeListener(BugReport.BugReportListener listener)
Add a new change listener.
|
private void |
fireChange() |
static java.lang.String |
getCallingMethod(int offset)
Find the method that called us.
|
static java.lang.StackTraceElement |
getCallingMethod(int offset,
java.lang.String className,
java.util.function.Predicate<java.lang.String> methodName)
Find the method that called the given method on the current stack trace.
|
java.lang.String |
getReportText(java.lang.String header)
Gets the full string that should be send as error report.
|
static ReportedException |
intercept(java.lang.Throwable t)
This should be called whenever you want to add more information to a given exception.
|
boolean |
isIncludeAllStackTraces()
Determines if this report should include the stack traces for all other threads.
|
boolean |
isIncludeData()
Determines if this report should include the data that was traced.
|
boolean |
isIncludeStatusReport()
Determines if this report should include a system status report
|
void |
removeChangeListener(BugReport.BugReportListener listener)
Remove a change listener.
|
void |
setIncludeAllStackTraces(boolean includeAllStackTraces)
Sets if this report should include the stack traces for all other threads.
|
void |
setIncludeData(boolean includeData)
Set if this report should include the data that was traced.
|
void |
setIncludeStatusReport(boolean includeStatusReport)
Set if this report should include a system status report
|
private static final long serialVersionUID
private boolean includeStatusReport
private boolean includeData
private boolean includeAllStackTraces
private final ReportedException exception
private final java.util.concurrent.CopyOnWriteArrayList<BugReport.BugReportListener> listeners
public BugReport(ReportedException e)
e
- The ReportedException
to use. No more data should be added after creating the report.public boolean isIncludeStatusReport()
true
to include it.public void setIncludeStatusReport(boolean includeStatusReport)
includeStatusReport
- if the status report should be includedpublic boolean isIncludeData()
true
to include it.public void setIncludeData(boolean includeData)
includeData
- if data should be includedpublic boolean isIncludeAllStackTraces()
true
to include it.public void setIncludeAllStackTraces(boolean includeAllStackTraces)
includeAllStackTraces
- if all stack traces should be includedpublic java.lang.String getReportText(java.lang.String header)
header
- header text for the error reportpublic void addChangeListener(BugReport.BugReportListener listener)
listener
- The listenerpublic void removeChangeListener(BugReport.BugReportListener listener)
listener
- The listenerprivate void fireChange()
public static ReportedException intercept(java.lang.Throwable t)
t
- The throwable that was thrown.ReportedException
to which you can add additional information.public static java.lang.String getCallingMethod(int offset)
offset
- How many methods to look back in the stack trace. 1 gives the method calling this method, 0 gives you getCallingMethod().public static java.lang.StackTraceElement getCallingMethod(int offset, java.lang.String className, java.util.function.Predicate<java.lang.String> methodName)
offset
- How many methods to look back in the stack trace.
1 gives the method calling this method, 0 gives you the method with the given name..className
- The name of the class to search formethodName
- The name of the method to search for