Skip to content

Commit 2d89c61

Browse files
authored
Fix: JNI + unsigned modes checking (#342)
1 parent ac30ee4 commit 2d89c61

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Sources/SwiftJavaTool/Commands/JExtractCommand.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ extension SwiftJava.JExtractCommand {
8686
config.writeEmptyFiles = writeEmptyFiles
8787
config.unsignedNumbersMode = unsignedNumbers
8888

89-
guard checkModeCompatibility() else {
90-
// check would have logged the reason for early exit.
91-
return
92-
}
89+
try checkModeCompatibility()
9390

9491
if let inputSwift = commonOptions.inputSwift {
9592
config.inputSwiftDirectory = inputSwift
@@ -108,18 +105,15 @@ extension SwiftJava.JExtractCommand {
108105
}
109106

110107
/// Check if the configured modes are compatible, and fail if not
111-
func checkModeCompatibility() -> Bool {
108+
func checkModeCompatibility() throws {
112109
if self.mode == .jni {
113110
switch self.unsignedNumbers {
114111
case .annotate:
115-
print("Error: JNI mode does not support '\(JExtractUnsignedIntegerMode.wrapGuava)' Unsigned integer mode! \(Self.helpMessage)")
116-
return false
112+
throw IllegalModeCombinationError("JNI mode does not support '\(JExtractUnsignedIntegerMode.wrapGuava)' Unsigned integer mode! \(Self.helpMessage)")
117113
case .wrapGuava:
118114
() // OK
119115
}
120116
}
121-
122-
return true
123117
}
124118
}
125119

@@ -140,5 +134,12 @@ extension SwiftJava.JExtractCommand {
140134

141135
}
142136

137+
struct IllegalModeCombinationError: Error {
138+
let message: String
139+
init(_ message: String) {
140+
self.message = message
141+
}
142+
}
143+
143144
extension JExtractGenerationMode: ExpressibleByArgument {}
144145
extension JExtractUnsignedIntegerMode: ExpressibleByArgument {}

0 commit comments

Comments
 (0)