Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved exception message #29

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/org/shipkit/auto/version/VersionSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ static boolean isWildcardSpec(String versionSpec) {
return versionSpec.matches("\\d+\\.\\d+\\.\\*");
}

private static String exceptionMessage(File versionFile) {
return "Problems deducting the version automatically. Expected correct 'version' property in file: " + versionFile + "\n" +
"Correct examples: 'version=1.0.*', 'version=2.10.100'";
private static String messageDetails(File versionFile) {
return " 'version' property in file: '" + versionFile.getName() + "'\n" +
" Correct examples: 'version=1.0.*', 'version=2.10.100'";
}

static class MissingVersionKey extends RuntimeException {
MissingVersionKey(File versionFile) {
super(exceptionMessage(versionFile));
super("Missing" + messageDetails(versionFile));
}
}

static class IncorrectVersionFormat extends RuntimeException {
IncorrectVersionFormat(File versionFile, Exception e) {
super(exceptionMessage(versionFile), e);
super("Invalid format of" + messageDetails(versionFile), e);
}
}
}
14 changes: 8 additions & 6 deletions src/test/groovy/org/shipkit/auto/version/VersionSpecTest.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.shipkit.auto.version

import spock.lang.Unroll

import static VersionSpec.readVersionSpec

Expand All @@ -20,28 +21,29 @@ class VersionSpecTest extends TmpFolderSpecification {
e.cause != null
}

def "bad format"() {
def "missing 'version' property"() {
def f = writeFile("noversion=missing")

when:
readVersionSpec(f)

then:
def e = thrown(VersionSpec.MissingVersionKey)
e.message == "Problems deducting the version automatically. Expected correct 'version' property in file: " + f + "\n" +
"Correct examples: 'version=1.0.*', 'version=2.10.100'"
e.message == "Missing 'version' property in file: '" + f.name + "'\n" +
" Correct examples: 'version=1.0.*', 'version=2.10.100'"
}

def "bad version format"() {
@Unroll
def "bad version format: #spec"() {
def f = writeFile("version=" + spec)

when:
readVersionSpec(f)

then:
def e = thrown(VersionSpec.IncorrectVersionFormat)
e.message == "Problems deducting the version automatically. Expected correct 'version' property in file: " + f + "\n" +
"Correct examples: 'version=1.0.*', 'version=2.10.100'"
e.message == "Invalid format of 'version' property in file: '" + f.name + "'\n" +
" Correct examples: 'version=1.0.*', 'version=2.10.100'"
e.cause != null

where:
Expand Down