From 0f9a91454064137863e0f58311d66233255d0548 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Fri, 1 Aug 2025 12:44:56 +0900 Subject: [PATCH] Fix: JNI + unsigned modes checking jextract JNI does not support the wrap mode; and our check was incorrect --- .../Commands/JExtractCommand.swift | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift index 03ca0cd7..105ace45 100644 --- a/Sources/SwiftJavaTool/Commands/JExtractCommand.swift +++ b/Sources/SwiftJavaTool/Commands/JExtractCommand.swift @@ -86,10 +86,7 @@ extension SwiftJava.JExtractCommand { config.writeEmptyFiles = writeEmptyFiles config.unsignedNumbersMode = unsignedNumbers - guard checkModeCompatibility() else { - // check would have logged the reason for early exit. - return - } + try checkModeCompatibility() if let inputSwift = commonOptions.inputSwift { config.inputSwiftDirectory = inputSwift @@ -108,18 +105,15 @@ extension SwiftJava.JExtractCommand { } /// Check if the configured modes are compatible, and fail if not - func checkModeCompatibility() -> Bool { + func checkModeCompatibility() throws { if self.mode == .jni { switch self.unsignedNumbers { case .annotate: - print("Error: JNI mode does not support '\(JExtractUnsignedIntegerMode.wrapGuava)' Unsigned integer mode! \(Self.helpMessage)") - return false + throw IllegalModeCombinationError("JNI mode does not support '\(JExtractUnsignedIntegerMode.wrapGuava)' Unsigned integer mode! \(Self.helpMessage)") case .wrapGuava: () // OK } } - - return true } } @@ -140,5 +134,12 @@ extension SwiftJava.JExtractCommand { } +struct IllegalModeCombinationError: Error { + let message: String + init(_ message: String) { + self.message = message + } +} + extension JExtractGenerationMode: ExpressibleByArgument {} extension JExtractUnsignedIntegerMode: ExpressibleByArgument {}