diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-28 13:38:05 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-09-28 16:45:25 +0200 |
commit | 17fbd7aefed098e78a6a639efdc7d4f29ed5b685 (patch) | |
tree | f68cf0b42f8088b4df630bbc0d90c2e10d1c2be8 /server/sonar-ce | |
parent | a795aa9c302449a3444f96842ab4084e50c8f49c (diff) | |
download | sonarqube-17fbd7aefed098e78a6a639efdc7d4f29ed5b685.tar.gz sonarqube-17fbd7aefed098e78a6a639efdc7d4f29ed5b685.zip |
Populate error type when CE task fails with TypedMessageException
When a CE task throws a TypedMessageException, then the provided error
type is propagated to db column ce_activity.error_type
Diffstat (limited to 'server/sonar-ce')
-rw-r--r-- | server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java | 4 | ||||
-rw-r--r-- | server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java | 16 |
2 files changed, 20 insertions, 0 deletions
diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java index adb63e13a23..bb4c43d8244 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java @@ -41,6 +41,7 @@ import org.sonar.db.ce.CeActivityDto; import org.sonar.db.ce.CeQueueDao; import org.sonar.db.ce.CeQueueDto; import org.sonar.server.computation.task.projectanalysis.component.VisitException; +import org.sonar.server.computation.task.step.TypedException; import org.sonar.server.organization.DefaultOrganizationProvider; import static com.google.common.base.Preconditions.checkArgument; @@ -131,6 +132,9 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue if (stacktrace != null) { activityDto.setErrorStacktrace(stacktrace); } + if (error instanceof TypedException) { + activityDto.setErrorType(((TypedException) error).getType()); + } } @CheckForNull diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index c54c5bbad1d..3626afc8a63 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -46,6 +46,7 @@ import org.sonar.db.ce.CeTaskTypes; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; import org.sonar.db.organization.OrganizationDto; +import org.sonar.server.computation.task.step.TypedException; import org.sonar.server.organization.DefaultOrganization; import org.sonar.server.organization.DefaultOrganizationProvider; @@ -236,6 +237,21 @@ public class InternalCeQueueImplTest { assertThat(activityDto.get().getErrorMessage()).isEqualTo(error.getMessage()); assertThat(activityDto.get().getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error)); + assertThat(activityDto.get().getErrorType()).isNull(); + } + + @Test + public void remove_saves_error_when_TypedMessageException_is_provided() { + Throwable error = new TypedException("aType", "aMessage"); + + CeTask task = submit(CeTaskTypes.REPORT, "PROJECT_1"); + Optional<CeTask> peek = underTest.peek(WORKER_UUID_1); + underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error); + + CeActivityDto activityDto = dbTester.getDbClient().ceActivityDao().selectByUuid(session, task.getUuid()).get(); + assertThat(activityDto.getErrorType()).isEqualTo("aType"); + assertThat(activityDto.getErrorMessage()).isEqualTo("aMessage"); + assertThat(activityDto.getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error)); } @Test |