refactor(sonar): replace if/throw with require/error

Sonar — replace hand-rolled 'throw IllegalArgumentException' / 'throw
IllegalStateException' with the idiomatic 'require { msg }' / 'error(msg)'.
Exception types preserved exactly (require throws IAE, error throws ISE).
This commit is contained in:
davotoula
2026-05-13 10:17:13 +02:00
parent 6960bdf497
commit 5e179326d4
4 changed files with 6 additions and 8 deletions
@@ -42,7 +42,7 @@ class PassphraseProvider(
): String {
fileFlag?.let { path ->
val text = File(path).readText().trimEnd('\n', '\r')
if (text.isEmpty()) throw IllegalArgumentException("--passphrase-file $path is empty")
require(text.isNotEmpty()) { "--passphrase-file $path is empty" }
return text
}
System.getenv(envName)?.takeIf { it.isNotEmpty() }?.let { return it }
@@ -52,10 +52,10 @@ class PassphraseProvider(
"No TTY and no passphrase source: set $envName or pass --passphrase-file PATH.",
)
val first = console.readPassword("$prompt: ").concatToString()
if (first.isEmpty()) throw IllegalArgumentException("empty passphrase")
require(first.isNotEmpty()) { "empty passphrase" }
if (confirm) {
val second = console.readPassword("Confirm passphrase: ").concatToString()
if (first != second) throw IllegalArgumentException("passphrases do not match")
require(first == second) { "passphrases do not match" }
}
return first
}
@@ -91,7 +91,7 @@ class SecretStore internal constructor(
when (secret.backend) {
MacosKeychainBackend.BACKEND_ID -> MacosKeychainBackend
SecretServiceBackend.BACKEND_ID -> SecretServiceBackend
else -> throw IllegalStateException("unknown keychain backend: ${secret.backend}")
else -> error("unknown keychain backend: ${secret.backend}")
}
}