From 61e0607a809309a921f6ddfab34c952f5533e325 Mon Sep 17 00:00:00 2001 From: Max Freudenberg <67329240+maxfreu@users.noreply.github.com> Date: Fri, 2 Jun 2023 10:54:33 +0200 Subject: [PATCH 1/2] remove throw from gdaljl_errorhandler The throw interrupts control flow on the C side, e.g. suppressing the closing of file descriptors when the error is caught by julia. --- src/error.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/error.jl b/src/error.jl index ac6beee..124f2ba 100644 --- a/src/error.jl +++ b/src/error.jl @@ -32,15 +32,13 @@ checking code decides it should throw. function gdaljl_errorhandler(class::CPLErr, errno::Cint, errmsg::Cstring) # function signature needs to match the one in __init__, and the signature # of the callback for a custom error handler in the GDAL docs - if class === CE_Failure - throw(GDALError(class, errno, unsafe_string(errmsg))) - end + # return C_NULL to suppress any error printing by gdal return C_NULL end "Check the last error type and throw a GDALError if it is a failure" function maybe_throw() - if cplgetlasterrortype() === CE_Failure + if cplgetlasterrortype() >= CE_Warning throw(GDALError()) end nothing From 6725599ba0374182b98a9f9e6c2562172712b73a Mon Sep 17 00:00:00 2001 From: Max Freudenberg <67329240+maxfreu@users.noreply.github.com> Date: Sat, 3 Jun 2023 19:10:19 +0200 Subject: [PATCH 2/2] fix comparison Co-authored-by: Martijn Visser --- src/error.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.jl b/src/error.jl index 124f2ba..ac7fb90 100644 --- a/src/error.jl +++ b/src/error.jl @@ -38,7 +38,7 @@ end "Check the last error type and throw a GDALError if it is a failure" function maybe_throw() - if cplgetlasterrortype() >= CE_Warning + if cplgetlasterrortype() >= CE_Failure throw(GDALError()) end nothing