error: GDALError (CE_Failure, code 4):not recognized as a supported file format

I am currently stuck with a strange issue in GDAL and do not understand how to solve it. I have a method inside an IO module:

read_image_file(filename::AbstractPath) =

This method is being called from another method:

function write_cog(output_path::SystemPath, dataset_path::AbstractPath)
    dataset = read_image_file(dataset_path)
    AG.copy(dataset; filename = string(output_path), driver = AG.getdriver("COG"))

and here it fails giving me the error

Exception has occurred: GDAL.GDALError
GDALError (CE_Failure, code 4):
	`.../temp.tif' not recognized as a supported file format.

When I run the same code through the debugger, it works well. Not sure how to solve this issue. Any help is much appreciated.

I find this solution in Stack Overflow:

but don’t see gdal.AllRegister() equivalent in ArchGDAL, could someone here point me in the right direction.

GDAL.jl has a gdalallregister function, but that is automatically called during module initialization, so that’s not the problem here. It looks more like your TIFF file might not be a GeoTIFF? GDAL cannot read TIFF files without geospatial metadata. You could check by trying if the file linked in this example can be loaded: Raster Data · ArchGDAL.jl.

I can confirm that the temp.tif file is created and I can read it fine using from the REPL

@visr thanks, I was able to resolve the issue, the problem was coming from this function I had:

function _save_array(
) where {T<:Real}
    # Read the DTM geotiff and extract the geotransform and projection
    dataset = read_image_file(input_dtm_path)
    projection = AG.getproj(dataset)
    geotransform = AG.getgeotransform(dataset)
    (m, n) = size(array2D)

    # Create a temporary dataset and write array2D to it
    # gds_out = AG.create(
    #     string(temp_dir),
    #     driver = AG.getdriver("GTiff"),
    #     width = m,
    #     height = n,
    #     nbands = 1,
    #     options = [
    #         "COMPRESS=DEFLATE",
    #         "COPY_SRC_OVERVIEWS=YES",
    #     ],
    #     dtype = T,
    # )
    # AG.setgeotransform!(gds_out, geotransform)
    # AG.setproj!(gds_out, projection)
    # AG.write!(gds_out, array2D[:, :], 1)
        driver = AG.getdriver("GTiff"),
        width = m,
        height = n,
        nbands = 1,
        dtype = T,
        options = opts,
    ) do ds
        band = AG.getband(ds, 1)
        AG.write!(band, array2D[:, :])
        AG.setgeotransform!(ds, geotransform)
        AG.setproj!(ds, projection)
                filename = string(temp_dir),
                driver = AG.getdriver("GTiff"),
                options = opts,

    return nothing


I made updates to it as per your advice on GitHub