Dont break grib parsing on corrupted data

This commit is contained in:
Guntis Smaukstelis
2025-05-05 22:56:10 +03:00
parent 4af8b261e9
commit cc9077360b
+8 -4
View File
@@ -17,10 +17,14 @@ object GribParser {
result <- if (ptr >= fileSize) {
IO.pure(acc.reverse)
} else {
for {
grib <- parseGrib(path, ptr)
nextResult <- loop(ptr + grib.length, grib :: acc)
} yield nextResult
parseGrib(path, ptr).attempt.flatMap {
case Right(grib) =>
loop(ptr + grib.length, grib :: acc)
case Left(error) =>
// Just log the error and end parsing
IO(println(s"Error parsing GRIB at position $ptr: ${error.getMessage}")) >>
IO.pure(acc.reverse)
}
}
} yield result
}