Deterministically creates an error code from the stack trace of the given cause . The code consists of three parts separated by DELIM: The first part depends on the root cause and the method that threw it The second part depends on the root cause an
(Throwable throwable)
| 75 | * @return A three-part error code |
| 76 | */ |
| 77 | public static ErrorCode of(Throwable throwable) { |
| 78 | var causalChain = Throwables.getCausalChain(throwable); |
| 79 | if (causalChain.size() > 1) { |
| 80 | var rootCause = causalChain.get(causalChain.size() - 1); |
| 81 | var parentOfRootCause = causalChain.get(causalChain.size() - 2); |
| 82 | var rootSpecificFrames = countTopmostFrames(rootCause.getStackTrace(), parentOfRootCause.getStackTrace()); |
| 83 | return new ErrorCode(throwable, rootCause, rootSpecificFrames); |
| 84 | } else { |
| 85 | return new ErrorCode(throwable, throwable, ALL_FRAMES); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | private String format(int value) { |
| 90 | // Cut off highest 12 bits (only leave 20 least significant bits) and XOR rest with cutoff |