Class BugReport

  • All Implemented Interfaces:
    Serializable

    public final class BugReport
    extends Object
    implements Serializable
    This class contains utility methods to create and handle a bug report.

    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.

    Handling Exceptions

    In your code, you should add try...catch blocks for any runtime exceptions that might happen. It is fine to catch throwable there.

    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.
    Since:
    10285
    See Also:
    Serialized Form
    • Method Detail

      • isIncludeStatusReport

        public boolean isIncludeStatusReport()
        Determines if this report should include a system status report
        Returns:
        true to include it.
        Since:
        10597
      • setIncludeStatusReport

        public void setIncludeStatusReport​(boolean includeStatusReport)
        Set if this report should include a system status report
        Parameters:
        includeStatusReport - if the status report should be included
        Since:
        10585
      • isIncludeData

        public boolean isIncludeData()
        Determines if this report should include the data that was traced.
        Returns:
        true to include it.
        Since:
        10597
      • setIncludeData

        public void setIncludeData​(boolean includeData)
        Set if this report should include the data that was traced.
        Parameters:
        includeData - if data should be included
        Since:
        10585
      • isIncludeAllStackTraces

        public boolean isIncludeAllStackTraces()
        Determines if this report should include the stack traces for all other threads.
        Returns:
        true to include it.
        Since:
        10597
      • setIncludeAllStackTraces

        public void setIncludeAllStackTraces​(boolean includeAllStackTraces)
        Sets if this report should include the stack traces for all other threads.
        Parameters:
        includeAllStackTraces - if all stack traces should be included
        Since:
        10585
      • getReportText

        public String getReportText​(String header)
        Gets the full string that should be send as error report.
        Parameters:
        header - header text for the error report
        Returns:
        The string.
        Since:
        10585
      • intercept

        public static ReportedException intercept​(Throwable t)
        This should be called whenever you want to add more information to a given exception.
        Parameters:
        t - The throwable that was thrown.
        Returns:
        A ReportedException to which you can add additional information.
      • getCallingMethod

        public static String getCallingMethod​(int offset)
        Find the method that called us.
        Parameters:
        offset - How many methods to look back in the stack trace. 1 gives the method calling this method, 0 gives you getCallingMethod().
        Returns:
        The method name.
      • getCallingMethod

        public static StackTraceElement getCallingMethod​(int offset,
                                                         String className,
                                                         Predicate<String> methodName)
        Find the method that called the given method on the current stack trace.
        Parameters:
        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 for
        methodName - The name of the method to search for
        Returns:
        The class and method name or null if it is unknown.