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) { result <- if (ptr >= fileSize) {
IO.pure(acc.reverse) IO.pure(acc.reverse)
} else { } else {
for { parseGrib(path, ptr).attempt.flatMap {
grib <- parseGrib(path, ptr) case Right(grib) =>
nextResult <- loop(ptr + grib.length, grib :: acc) loop(ptr + grib.length, grib :: acc)
} yield nextResult 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 } yield result
} }