private static void updateError(CeActivityDto activityDto, @Nullable Throwable error) { if (error == null) { return; } if (error instanceof VisitException && error.getCause() != null) { activityDto.setErrorMessage(format("%s (%s)", error.getCause().getMessage(), error.getMessage())); } else { activityDto.setErrorMessage(error.getMessage()); } String stacktrace = getStackTraceForPersistence(error); if (stacktrace != null) { activityDto.setErrorStacktrace(stacktrace); } if (error instanceof TypedException) { activityDto.setErrorType(((TypedException) error).getType()); } }
@Override public void fail(DbSession dbSession, CeQueueDto task, @Nullable String errorType, @Nullable String errorMessage) { checkState(IN_PROGRESS.equals(task.getStatus()), "Task is not in-progress and can't be marked as failed [uuid=%s]", task.getUuid()); CeActivityDto activityDto = new CeActivityDto(task); activityDto.setStatus(CeActivityDto.Status.FAILED); activityDto.setErrorType(errorType); activityDto.setErrorMessage(errorMessage); updateExecutionFields(activityDto); remove(dbSession, task, activityDto); }
@Test public void formatActivity_with_both_error_message_and_stacktrace() { CeActivityDto dto = newActivity("UUID", "COMPONENT_UUID", CeActivityDto.Status.FAILED, null) .setErrorMessage("error msg") .setErrorStacktrace("error stacktrace") .setErrorType("anErrorType"); Ce.Task task = underTest.formatActivity(db.getSession(), Collections.singletonList(dto)).iterator().next(); assertThat(task.getErrorMessage()).isEqualTo(dto.getErrorMessage()); assertThat(task.getErrorStacktrace()).isEqualTo(dto.getErrorStacktrace()); assertThat(task.getErrorType()).isEqualTo(dto.getErrorType()); }
private static void updateError(CeActivityDto activityDto, @Nullable Throwable error) { if (error == null) { return; } if (error instanceof VisitException && error.getCause() != null) { activityDto.setErrorMessage(format("%s (%s)", error.getCause().getMessage(), error.getMessage())); } else { activityDto.setErrorMessage(error.getMessage()); } String stacktrace = getStackTraceForPersistence(error); if (stacktrace != null) { activityDto.setErrorStacktrace(stacktrace); } if (error instanceof TypedException) { activityDto.setErrorType(((TypedException) error).getType()); } }