From 8cfbc60feac36daa939e8598f645946f0dfdaa56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Pfeuffer?= Date: Wed, 11 Nov 2020 11:37:24 +0100 Subject: [PATCH] Distinguish between errors with and without details --- .../IntegrateChangesFromWorkdirException.java | 5 +++-- ...IntegrateChangesFromWorkdirExceptionTest.java | 16 +++++++++++++++- .../src/BackendErrorNotification.tsx | 12 +++++++++++- .../src/main/resources/locales/de/plugins.json | 6 +++++- .../src/main/resources/locales/en/plugins.json | 10 +++++++--- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirException.java b/scm-core/src/main/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirException.java index d0dcb28e65..f8dc0ba2d0 100644 --- a/scm-core/src/main/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirException.java +++ b/scm-core/src/main/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirException.java @@ -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 { diff --git a/scm-core/src/test/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirExceptionTest.java b/scm-core/src/test/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirExceptionTest.java index 6a4580361e..d990a64ef7 100644 --- a/scm-core/src/test/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirExceptionTest.java +++ b/scm-core/src/test/java/sonia/scm/repository/spi/IntegrateChangesFromWorkdirExceptionTest.java @@ -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); } } diff --git a/scm-ui/ui-components/src/BackendErrorNotification.tsx b/scm-ui/ui-components/src/BackendErrorNotification.tsx index 01386a917a..5b0aac0d9b 100644 --- a/scm-ui/ui-components/src/BackendErrorNotification.tsx +++ b/scm-ui/ui-components/src/BackendErrorNotification.tsx @@ -71,7 +71,17 @@ class BackendErrorNotification extends React.Component { renderAdditionalMessages = () => { const { error, t } = this.props; if (error.additionalMessages) { - return error.additionalMessages.map(a => a.key ? t(`errors.${a.key}.description`) : a.message).map(m =>

{m}

); + return ( + <> +
+ {error.additionalMessages + .map(a => (a.key ? t(`errors.${a.key}.description`) : a.message)) + .map(m => ( +

{m}

+ ))} +
+ + ); } }; diff --git a/scm-webapp/src/main/resources/locales/de/plugins.json b/scm-webapp/src/main/resources/locales/de/plugins.json index 2226986629..300fa3d17a 100644 --- a/scm-webapp/src/main/resources/locales/de/plugins.json +++ b/scm-webapp/src/main/resources/locales/de/plugins.json @@ -197,7 +197,11 @@ }, "CHRM7IQzo1": { "displayName": "Änderung des Repositories nicht möglich", - "description": "Die gewünschte Änderung am Repository konnte nicht durchgeführt werden. Höchst wahrscheinlich liegt dieses an installierten Plugins mit Hooks oder nativen Hooks. Folgend sind eventuelle weitere Meldungen." + "description": "Die gewünschte Änderung am Repository konnte nicht durchgeführt werden. Höchst wahrscheinlich liegt dieses an Prüfungen von Plugins. Bitte prüfen Sie die Einstellungen. Im Folgenden finden Sie weitere Meldungen zu dem Fehler:" + }, + "ASSG1ehZ01": { + "displayName": "Änderung des Repositories nicht möglich", + "description": "Die gewünschte Änderung am Repository konnte nicht durchgeführt werden. Es gab keine weiteren Meldungen." }, "thbsUFokjk": { "displayName": "Unerlaubte Änderung eines Schlüsselwerts", diff --git a/scm-webapp/src/main/resources/locales/en/plugins.json b/scm-webapp/src/main/resources/locales/en/plugins.json index 246f667e7b..8d6086ac19 100644 --- a/scm-webapp/src/main/resources/locales/en/plugins.json +++ b/scm-webapp/src/main/resources/locales/en/plugins.json @@ -197,7 +197,11 @@ }, "CHRM7IQzo1": { "displayName": "Could not modify repository", - "description": "The requested modification to the repository was rejected. Most probably this was due to plugins with repository hooks or native hooks. Following are potential additional messages." + "description": "The requested modification to the repository was rejected. The most likely reason for this are checks from plugins. Please check your settings. See the following messages for more details:" + }, + "ASSG1ehZ01": { + "displayName": "Could not modify repository", + "description": "The requested modification to the repository was rejected. There were no more messages." }, "thbsUFokjk": { "displayName": "Illegal change of an identifier", @@ -205,7 +209,7 @@ }, "40RaYIeeR1": { "displayName": "No changes were made", - "description": "No changes were made to the files of the repository. Therefor no new commit could be created. Possibly changes cannot be applied due to an .ignore-File definition." + "description": "No changes were made to the files of the repository. Therefore no new commit could be created. Possibly changes cannot be applied due to an .ignore-File definition." }, "ERS2vYb7U1": { "displayName": "Illegal change of namespace", @@ -213,7 +217,7 @@ }, "4iRct4avG1": { "displayName": "The revisions have unrelated histories", - "description": "The revisions have unrelated histories. Therefor there is no common commit to compare with." + "description": "The revisions have unrelated histories. Therefore there is no common commit to compare with." }, "65RdZ5atX1": { "displayName": "Error removing plugin files",