diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-19 15:30:26 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-02-19 15:30:26 +0100 |
commit | c90c909c19c3e8004a070d64aae235d5f1ca92f9 (patch) | |
tree | ad339fb7fcbd350f665babb04c52538c2b8b1f03 /server | |
parent | 688d9e3a2bca75972a7e6cb7833b780609d38c18 (diff) | |
download | sonarqube-c90c909c19c3e8004a070d64aae235d5f1ca92f9.tar.gz sonarqube-c90c909c19c3e8004a070d64aae235d5f1ca92f9.zip |
SONAR-6187 Replace MessageException instead of IllegalStateException and add more info in error message
Diffstat (limited to 'server')
2 files changed, 17 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java index 23d2e79e95f..fbdc4b17b94 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration.java @@ -23,6 +23,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.core.persistence.Database; import org.sonar.server.db.migrations.BaseDataChange; @@ -53,6 +54,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration private static final String COMPLIANCE_NAME = "Compliance"; private static final String COMPLIANCE_KEY_SUFFIX = "_COMPLIANCE"; + private static final String ERROR_SUFFIX = "Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."; + private final System2 system; public AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration(Database db, System2 system) { @@ -229,7 +233,7 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration }, null); if (characteristic != null) { if (characteristic.getParentId() != null) { - throw new IllegalStateException(String.format("'%s' must be a characteristic", characteristic.getName())); + throw MessageException.of(String.format("'%s' must be a characteristic. " + ERROR_SUFFIX, characteristic.getName())); } } return characteristic; @@ -246,9 +250,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigration if (characteristic != null) { Integer parentId = characteristic.getParentId(); if (parentId == null) { - throw new IllegalStateException(String.format("'%s' must be a sub-characteristic", characteristic.getName())); + throw MessageException.of(String.format("'%s' must be a sub-characteristic. " + ERROR_SUFFIX, characteristic.getName())); } else if (!characteristic.getParentId().equals(parent.getId())) { - throw new IllegalStateException(String.format("'%s' must be defined under '%s'", characteristic.getName(), parent.getName())); + throw MessageException.of(String.format("'%s' must be defined under '%s'. " + ERROR_SUFFIX, characteristic.getName(), parent.getName())); } } return characteristic; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java index a1ca4e5fe1c..bc53a8a43c0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v501/AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; import org.sonar.api.utils.DateUtils; +import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; import org.sonar.core.persistence.TestDatabase; import org.sonar.server.db.migrations.DatabaseMigration; @@ -93,7 +94,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationT migration.execute(); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Usability' must be a characteristic"); + assertThat(e).isInstanceOf(MessageException.class).hasMessage( + "'Usability' must be a characteristic. Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."); } } @@ -105,7 +108,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationT migration.execute(); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Compliance' must be a sub-characteristic"); + assertThat(e).isInstanceOf(MessageException.class).hasMessage( + "'Compliance' must be a sub-characteristic. Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."); } } @@ -117,7 +122,9 @@ public class AddCharacteristicUsabilityAndSubCharacteristicsComplianceMigrationT migration.execute(); fail(); } catch (Exception e) { - assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("'Reusability Compliance' must be defined under 'Reusability'"); + assertThat(e).isInstanceOf(MessageException.class).hasMessage( + "'Reusability Compliance' must be defined under 'Reusability'. Please restore your DB backup, start the previous version of SonarQube " + + "and update your SQALE model to fix this issue before trying again to run the migration."); } } |