Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TraceableException.java « exceptions « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d436477d2010e353cccca047753ff08036810c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package it.niedermann.nextcloud.deck.exceptions;

import it.niedermann.nextcloud.deck.DeckLog;

public class TraceableException extends RuntimeException {

    private TraceableException(String message, Throwable cause) {
        super(message, cause);
    }

    public static void makeTraceableIfFails(Runnable runnable, Object... args) {
        try {
            runnable.run();
        } catch (TraceableException t) {
            throw t;
        } catch (Throwable t) {
            final StringBuilder message = new StringBuilder("Sorry, a wild error appeared!\n\n" +
                    "⚠️ If you want to tell us about the following issue, " +
                    "please make sure to censor sensitive data beforehand! ⚠️\n\n" +
                    "Failed to run traceable code");
            if (args != null && args.length > 0) {
                message.append(" with arguments:\n");
                for (Object arg : args) {
                    message.append(arg == null ? "null" : arg.toString()).append("\n");
                }
            } else {
                message.append(":\n");
            }

            message.append("Cause: ").append(t.getLocalizedMessage());
            TraceableException ex = new TraceableException(message.toString(), t);
            DeckLog.logError(ex);
            throw ex;
        }
    }
}