From ccc98c8747b6f0e19cb2b9762d9589e510a0bace Mon Sep 17 00:00:00 2001 From: sllynn Date: Fri, 29 Nov 2024 18:51:36 +0000 Subject: [PATCH] catch and explain GDAL calc errors --- .../mosaic/core/raster/operator/gdal/GDALCalc.scala | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/scala/com/databricks/labs/mosaic/core/raster/operator/gdal/GDALCalc.scala b/src/main/scala/com/databricks/labs/mosaic/core/raster/operator/gdal/GDALCalc.scala index 4f9177ed7..3306da842 100644 --- a/src/main/scala/com/databricks/labs/mosaic/core/raster/operator/gdal/GDALCalc.scala +++ b/src/main/scala/com/databricks/labs/mosaic/core/raster/operator/gdal/GDALCalc.scala @@ -5,6 +5,9 @@ import com.databricks.labs.mosaic.core.raster.gdal.{MosaicRasterGDAL, MosaicRast import com.databricks.labs.mosaic.utils.SysUtils import org.gdal.gdal.gdal +import java.nio.file.{Files, Paths} +import scala.util.Try + /** GDALCalc is a helper object for executing GDAL Calc commands. */ object GDALCalc { @@ -35,6 +38,14 @@ object GDALCalc { val toRun = effectiveCommand.replace("gdal_calc", gdal_calc) val commandRes = SysUtils.runCommand(s"python3 $toRun") val errorMsg = gdal.GetLastErrorMsg + val size = Try(Files.size(Paths.get(resultPath))).getOrElse( + { + val msg = "Error during GDAL calc operation: " + + s"file $resultPath " + + s"with command '$effectiveCommand'. GDAL returned error: $errorMsg" + throw new Exception(msg) + } + ) val result = GDAL.raster(resultPath, resultPath, None) val createInfo = Map( "path" -> resultPath,