Skip to content

Commit

Permalink
Shorten state checks (#1321)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Mar 7, 2025
1 parent ac75467 commit 706ff36
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class AppendableMavenRepository(
}

fun build(): Path {
if (!::existingJar.isInitialized) error("No jar file provided for $coordinate")
check(::existingJar.isInitialized) { "No jar file provided for $coordinate" }
return existingJar.also {
check(it.exists()) { "Jar file doesn't exist for $coordinate in: $it" }
check(it.isRegularFile()) { "Jar is not a regular file for $coordinate in: $it" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fun ZipFile.getContent(entryName: String): String {
}

fun ZipFile.getStream(entryName: String): InputStream {
val entry = getEntry(entryName) ?: error("Entry $entryName not found in all entries: ${entries().toList()}")
val entry = requireNotNull(getEntry(entryName)) { "Entry $entryName not found in all entries: ${entries().toList()}" }
return getInputStream(entry)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fun runProcess(
val err = process.errorStream.bufferedReader().use { it.readText() }
val out = process.inputStream.bufferedReader().use { it.readText() }

if (exitCode != 0 || err.isNotEmpty()) {
error("Error occurred when running command line: $err")
check(exitCode == 0 && err.isEmpty()) {
"Error occurred when running command line: $err"
}

return out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public data class TransformerContext @JvmOverloads constructor(
public fun relocators(relocators: Set<Relocator>): Builder = apply { this.relocators = relocators }
public fun build(): TransformerContext = TransformerContext(
path = path,
inputStream = inputStream ?: error("inputStream is required"),
inputStream = requireNotNull(inputStream) { "inputStream is required" },
relocators = relocators,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class ServiceFileTransformerTest : BaseTransformerTest<ServiceFileTransformer>()
}

fun ZipFile.getStream(entryName: String): InputStream {
val entry = getEntry(entryName) ?: error("Entry $entryName not found in all entries: ${entries().toList()}")
val entry = requireNotNull(getEntry(entryName)) { "Entry $entryName not found in all entries: ${entries().toList()}" }
return getInputStream(entry)
}

Expand Down

0 comments on commit 706ff36

Please # to comment.