Skip to content

Commit 3b8ac10

Browse files
committed
Print an error message when the expected input file is missing
1 parent deaedcd commit 3b8ac10

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/kotlin/de/ronny_h/aoc/AdventOfCode.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package de.ronny_h.aoc
22

3-
import kotlin.io.path.Path
4-
import kotlin.io.path.readText
53
import kotlin.time.TimedValue
64
import kotlin.time.measureTimedValue
75

@@ -13,11 +11,16 @@ abstract class AdventOfCode<T>(val year: Int, val day: Int) {
1311
val input = readInput()
1412
println("Day $day $year - ${this::class.simpleName} - part 1")
1513
printAndCheck(input, ::part1, expectedPart1)
14+
println()
1615
println("Day $day $year - ${this::class.simpleName} - part 2")
1716
printAndCheck(input, ::part2, expectedPart2)
1817
}
1918

20-
fun readInput() = AdventOfCode::class.java.getResource("/$year/Day${paddedDay()}.txt")!!.readText().trim().lines()
19+
fun readInput(): List<String> {
20+
val inputFile = "/$year/Day${paddedDay()}.txt"
21+
return AdventOfCode::class.java.getResource(inputFile)?.readText()?.trim()?.lines()
22+
?: error("The input file for day $day, year $year could not be found. Expected at '$inputFile' in the resources folder.")
23+
}
2124

2225
private fun paddedDay(): String = day.toString().padStart(2, '0')
2326

0 commit comments

Comments
 (0)