Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch error in write to remove broken file #483

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ Keyword arguments are passed to the `write` method for the backend.
function Base.write(
filename::AbstractString, A::AbstractRaster; source=_sourcetype(filename), kw...
)
write(filename, source, A; kw...)
try
write(filename, source, A; kw...)
catch e
if isfile(filename)
rm(filename)
end
rethrow(e)
end
end
Base.write(A::AbstractRaster; kw...) = write(filename(A), A; kw...)
function Base.write(
Expand Down
10 changes: 10 additions & 0 deletions test/sources/ncdatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ end
@test size2 > size1*1.8 # two variable
isfile(fn) && rm(fn)

# test erroring doesn't write file
fn = "test_broken.nc"
try
write(fn, r1; deflatelevel="a")
catch e
end
@test !isfile(fn)
isfile(fn) && rm(fn)


@testset "non allowed values" begin
# TODO return this test when the changes in NCDatasets.jl settle
# @test_throws ArgumentError write(filename, convert.(Union{Missing,Float16}, geoA))
Expand Down
Loading