Skip to content

Commit ccc98c8

Browse files
committed
catch and explain GDAL calc errors
1 parent 58c3ba5 commit ccc98c8

File tree

1 file changed

+11
-0
lines changed
  • src/main/scala/com/databricks/labs/mosaic/core/raster/operator/gdal

1 file changed

+11
-0
lines changed

src/main/scala/com/databricks/labs/mosaic/core/raster/operator/gdal/GDALCalc.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import com.databricks.labs.mosaic.core.raster.gdal.{MosaicRasterGDAL, MosaicRast
55
import com.databricks.labs.mosaic.utils.SysUtils
66
import org.gdal.gdal.gdal
77

8+
import java.nio.file.{Files, Paths}
9+
import scala.util.Try
10+
811
/** GDALCalc is a helper object for executing GDAL Calc commands. */
912
object GDALCalc {
1013

@@ -35,6 +38,14 @@ object GDALCalc {
3538
val toRun = effectiveCommand.replace("gdal_calc", gdal_calc)
3639
val commandRes = SysUtils.runCommand(s"python3 $toRun")
3740
val errorMsg = gdal.GetLastErrorMsg
41+
val size = Try(Files.size(Paths.get(resultPath))).getOrElse(
42+
{
43+
val msg = "Error during GDAL calc operation: " +
44+
s"file $resultPath " +
45+
s"with command '$effectiveCommand'. GDAL returned error: $errorMsg"
46+
throw new Exception(msg)
47+
}
48+
)
3849
val result = GDAL.raster(resultPath, resultPath, None)
3950
val createInfo = Map(
4051
"path" -> resultPath,

0 commit comments

Comments
 (0)