@Override public Response toResponse(Throwable throwable) { if (throwable instanceof WebApplicationException) { return ((WebApplicationException) throwable).getResponse(); } log.warn(throwable, "Request failed for %s", request.getRequestURI()); ResponseBuilder responseBuilder = Response.serverError() .header(CONTENT_TYPE, TEXT_PLAIN); if (includeExceptionInResponse) { responseBuilder.entity(Throwables.getStackTraceAsString(throwable)); } else { responseBuilder.entity("Exception processing request"); } return responseBuilder.build(); } }
Future<Void> sendError(Throwable error) { LOG.debug("Send error to Client: {}", Throwables.getStackTraceAsString(error)); return clientRpc.call(new Error(Throwables.getStackTraceAsString(error))); }
private String printSubsequentFailure( StackTraceElement[] baseTraceFrames, AssertionError toPrint) { Exception e = new RuntimeException("__EXCEPTION_MARKER__", toPrint); e.setStackTrace(baseTraceFrames); String s = Throwables.getStackTraceAsString(e); // Force single line reluctant matching return s.replaceFirst("(?s)^.*?__EXCEPTION_MARKER__.*?Caused by:\\s+", ""); }
private void processTemplates(Set<? extends Element> templates) { for (TypeElement templateType : ElementFilter.typesIn(templates)) { try { generateTemplateType(templateType); } catch (Exception ex) { processingEnv.getMessager() .printMessage(Diagnostic.Kind.ERROR, ex.getMessage() + "\n\n" + Throwables.getStackTraceAsString(ex), templateType); } } }
@Override public void onStartContainerError(ContainerId containerId, Throwable t) { if (eventSubmitter.isPresent()) { eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.CONTAINER_START_ERROR, GobblinYarnMetricTagNames.CONTAINER_ID, containerId.toString(), GobblinYarnEventConstants.EventMetadata.ERROR_EXCEPTION, Throwables.getStackTraceAsString(t)); } LOGGER.error(String.format("Failed to start container %s due to error %s", containerId, t)); containerMap.remove(containerId); }
@Override public void onStopContainerError(ContainerId containerId, Throwable t) { if (eventSubmitter.isPresent()) { eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.CONTAINER_STOP_ERROR, GobblinYarnMetricTagNames.CONTAINER_ID, containerId.toString(), GobblinYarnEventConstants.EventMetadata.ERROR_EXCEPTION, Throwables.getStackTraceAsString(t)); } LOGGER.error(String.format("Failed to stop container %s due to error %s", containerId, t)); } }
@Override public final void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { LOG.error(String.format("[%s] Closing channel due to exception in pipeline.", name()), cause); if (lastHeader != null) { // There's an RPC waiting for a reply. Exception was most probably caught while processing // the RPC, so send an error. ctx.channel().write(new Rpc.MessageHeader(lastHeader.id, Rpc.MessageType.ERROR)); ctx.channel().writeAndFlush(Throwables.getStackTraceAsString(cause)); lastHeader = null; } ctx.close(); }
@Override public void onGetContainerStatusError(ContainerId containerId, Throwable t) { if (eventSubmitter.isPresent()) { eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.CONTAINER_GET_STATUS_ERROR, GobblinYarnMetricTagNames.CONTAINER_ID, containerId.toString(), GobblinYarnEventConstants.EventMetadata.ERROR_EXCEPTION, Throwables.getStackTraceAsString(t)); } LOGGER.error(String.format("Failed to get status for container %s due to error %s", containerId, t)); }
@Override public void onError(Throwable t) { if (eventSubmitter.isPresent()) { eventSubmitter.get().submit(GobblinYarnEventConstants.EventNames.ERROR, GobblinYarnEventConstants.EventMetadata.ERROR_EXCEPTION, Throwables.getStackTraceAsString(t)); } LOGGER.error("Received error: " + t, t); this.done = true; eventBus.post(new ClusterManagerShutdownRequest()); } }
public <T> DescriptionBuilder expected(String reason) { description.appendText(reason).appendText("\nExpected to not be reachable"); description.appendText("\nLocation: ").appendText( Throwables.getStackTraceAsString(new Exception())); matches = false; return this; }
/** * If not already present, set the {@link ConfigurationKeys#TASK_FAILURE_EXCEPTION_KEY} to a {@link String} * representation of the given {@link Throwable}. */ public void setTaskFailureException(Throwable taskFailureException) { if (!this.contains(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY)) { this.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, Throwables.getStackTraceAsString(taskFailureException)); } }
@GwtIncompatible // getStackTraceAsString(Throwable) public void testGetStackTraceAsString() { class StackTraceException extends Exception { StackTraceException(String message) { super(message); } } StackTraceException e = new StackTraceException("my message"); String firstLine = quote(e.getClass().getName() + ": " + e.getMessage()); String secondLine = "\\s*at " + ThrowablesTest.class.getName() + "\\..*"; String moreLines = "(?:.*\n?)*"; String expected = firstLine + "\n" + secondLine + "\n" + moreLines; assertThat(getStackTraceAsString(e)).matches(expected); }
private <T> void addError(String reason, T actual, Matcher<? super T> matcher) { description.appendText(reason) .appendText("\nExpected: ") .appendDescriptionOf(matcher) .appendText("\n but: "); matcher.describeMismatch(actual, description); description.appendText("\nLocation: ") .appendText(Throwables.getStackTraceAsString(new Exception())); matches = false; }
@Override public void run() { int id = index.getAndIncrement(); for (Integer e : sets.get(id)) { BiConsumer<A, Integer> operation = operations.get( ThreadLocalRandom.current().nextInt(operations.size())); try { operation.accept(collection, e); } catch (Throwable t) { failures.add(String.format("Failed: key %s on operation %s%n%s", e, operation, Throwables.getStackTraceAsString(t))); throw t; } } } }
void checkNoExceptionRaised() { List<Throwable> errors = getTasksErrors(); if ( !errors.isEmpty() ) { StringBuilder message = new StringBuilder( 1024 ); message.append( "There are expected no exceptions during the test, but " ) .append( errors.size() ).append( " raised:" ); for ( Throwable throwable : errors ) { String stacktrace = Throwables.getStackTraceAsString( throwable ); message.append( '\n' ).append( stacktrace ); } Assert.fail( message.toString() ); } }
private boolean syncMetadata(RpcContext rpcContext, LockedInodePath inodePath, LockingScheme lockingScheme, DescendantType syncDescendantType) { boolean result; if (!lockingScheme.shouldSync()) { return false; } try { result = syncMetadataInternal(rpcContext, inodePath, lockingScheme, syncDescendantType, populateStatusCache(inodePath.getUri(), syncDescendantType)); } catch (Exception e) { LOG.warn("Sync metadata for path {} encountered exception {}", inodePath.getUri(), Throwables.getStackTraceAsString(e)); return false; } return result; }
assertNull( "Throwable from other thread: " + (throwable == null ? null : Throwables.getStackTraceAsString(throwable)), throwableFromOtherThread.get());
private void failTask(Throwable t) { LOG.error(String.format("Task %s failed", this.taskId), t); this.taskState.setWorkingState(WorkUnitState.WorkingState.FAILED); this.taskState.setProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY, Throwables.getStackTraceAsString(t)); // Send task failure event FailureEventBuilder failureEvent = new FailureEventBuilder(FAILED_TASK_EVENT); failureEvent.setRootCause(t); failureEvent.addMetadata(TASK_STATE, this.taskState.toString()); failureEvent.submit(taskContext.getTaskMetrics().getMetricContext()); }
public TaskStatus run(TaskToolbox toolbox) { try { return runInternal(toolbox); } catch (Exception e) { log.error(e, "Encountered exception while running task."); final String errorMsg = Throwables.getStackTraceAsString(e); toolbox.getTaskReportFileWriter().write(getTaskCompletionReports(errorMsg)); return TaskStatus.failure( task.getId(), errorMsg ); } }
@Override public TaskStatus run(TaskToolbox toolbox) { try { return runInternal(toolbox); } catch (Exception e) { log.error(e, "Encountered exception while running task."); final String errorMsg = Throwables.getStackTraceAsString(e); toolbox.getTaskReportFileWriter().write(getTaskCompletionReports(errorMsg)); return TaskStatus.failure( task.getId(), errorMsg ); } }