Distinguish between errors with and without details

This commit is contained in:
René Pfeuffer
2020-11-11 11:37:24 +01:00
parent 5b44be5e5b
commit 8cfbc60fea
5 changed files with 41 additions and 8 deletions

View File

@@ -37,7 +37,8 @@ import static sonia.scm.ContextEntry.ContextBuilder.entity;
public class IntegrateChangesFromWorkdirException extends ExceptionWithContext {
private static final String CODE = "CHRM7IQzo1";
static final String CODE_WITH_ADDITIONAL_MESSAGES = "CHRM7IQzo1";
static final String CODE_WITHOUT_ADDITIONAL_MESSAGES = "ASSG1ehZ01";
private static final Pattern SCM_MESSAGE_PATTERN = Pattern.compile(".*\\[SCM\\] (.*)");
@@ -55,7 +56,7 @@ public class IntegrateChangesFromWorkdirException extends ExceptionWithContext {
@Override
public String getCode() {
return CODE;
return getAdditionalMessages().isEmpty()? CODE_WITHOUT_ADDITIONAL_MESSAGES : CODE_WITH_ADDITIONAL_MESSAGES;
}
public static class MessageExtractor {

View File

@@ -30,6 +30,8 @@ import sonia.scm.repository.Repository;
import java.util.regex.Pattern;
import static org.assertj.core.api.Assertions.assertThat;
import static sonia.scm.repository.spi.IntegrateChangesFromWorkdirException.CODE_WITHOUT_ADDITIONAL_MESSAGES;
import static sonia.scm.repository.spi.IntegrateChangesFromWorkdirException.CODE_WITH_ADDITIONAL_MESSAGES;
import static sonia.scm.repository.spi.IntegrateChangesFromWorkdirException.forMessage;
import static sonia.scm.repository.spi.IntegrateChangesFromWorkdirException.withPattern;
@@ -39,11 +41,13 @@ class IntegrateChangesFromWorkdirExceptionTest {
@Test
void shouldExtractMessagesWithDefaultPrefix() {
IntegrateChangesFromWorkdirException exception = forMessage(REPOSITORY, "prefix [SCM] line 1\nprefix [SCM] line 2\nirrelevant line\n");
IntegrateChangesFromWorkdirException exception =
forMessage(REPOSITORY, "prefix [SCM] line 1\nprefix [SCM] line 2\nirrelevant line\n");
assertThat(exception.getAdditionalMessages())
.extracting("message")
.containsExactly("line 1", "line 2");
assertThat(exception.getCode()).isEqualTo(CODE_WITH_ADDITIONAL_MESSAGES);
}
@Test
@@ -55,5 +59,15 @@ class IntegrateChangesFromWorkdirExceptionTest {
assertThat(exception.getAdditionalMessages())
.extracting("message")
.containsExactly("line");
assertThat(exception.getCode()).isEqualTo(CODE_WITH_ADDITIONAL_MESSAGES);
}
@Test
void shouldCreateSpecialMessageForMissingAdditionalMessages() {
IntegrateChangesFromWorkdirException exception =
forMessage(REPOSITORY, "There is no message");
assertThat(exception.getAdditionalMessages()).isEmpty();
assertThat(exception.getCode()).isEqualTo(CODE_WITHOUT_ADDITIONAL_MESSAGES);
}
}