Skip to content

Commit eb2937f

Browse files
Refactor Groovy version detection to use custom exception
Replaced raw RuntimeException with GroovyVersionException in ClassWrangler. This improves maintainability and error handling by providing a more specific exception type and preserving the original cause. Key changes: - Created GroovyVersionException (unchecked) in util package. - Updated ClassWrangler.getGroovyVersion() to throw GroovyVersionException. - Updated ClassWrangler.getGroovyJar() to throw GroovyVersionException. - Included the original cause in the new exception for better debuggability. Co-authored-by: keeganwitt <64612+keeganwitt@users.noreply.github.com>
1 parent d5a3f18 commit eb2937f

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/main/java/org/codehaus/gmavenplus/util/ClassWrangler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public Version getGroovyVersion() {
124124
try {
125125
return Version.parseFromString(getGroovyVersionString());
126126
} catch (Exception e) {
127-
throw new RuntimeException("Unable to determine Groovy version. Is Groovy declared as a dependency?");
127+
throw new GroovyVersionException("Unable to determine Groovy version. Is Groovy declared as a dependency?", e);
128128
}
129129
}
130130

@@ -259,7 +259,7 @@ protected String getGroovyJar() {
259259

260260
return groovyJar;
261261
} catch (ClassNotFoundException e) {
262-
throw new RuntimeException("Unable to determine Groovy version. Is Groovy declared as a dependency?");
262+
throw new GroovyVersionException("Unable to determine Groovy version. Is Groovy declared as a dependency?", e);
263263
}
264264
}
265265

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.codehaus.gmavenplus.util;
2+
3+
/**
4+
* Exception thrown when Groovy version cannot be determined.
5+
*
6+
* @author Keegan Witt
7+
* @since 4.3.2
8+
*/
9+
public class GroovyVersionException extends RuntimeException {
10+
11+
/**
12+
* Constructs a new GroovyVersionException with the specified message.
13+
*
14+
* @param message the detail message
15+
*/
16+
public GroovyVersionException(final String message) {
17+
super(message);
18+
}
19+
20+
/**
21+
* Constructs a new GroovyVersionException with the specified message and cause.
22+
*
23+
* @param message the detail message
24+
* @param cause the cause
25+
*/
26+
public GroovyVersionException(final String message, final Throwable cause) {
27+
super(message, cause);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)