JuliaAstro / FITSIO.jl

Flexible Image Transport System (FITS) file support for Julia
http://juliaastro.org/FITSIO.jl/
MIT License
55 stars 29 forks source link

update hdu ext after deletion #176

Closed jishnub closed 2 years ago

jishnub commented 2 years ago

Alter the ext of an ImageHDU if it is deleted, so that functions don't accidentally try to access the non-existent HDU in the file.

master

julia> f = FITS(tempname(), "w");

julia> write(f, [1]);

julia> write(f, ones(1,1)*2);

julia> hdu = f[2]
File: /tmp/jl_GKwZG1
HDU: 2
Mode: read-write
Type: Image
Datatype: Float64
Datasize: (1, 1)

julia> deleteat!(f, 2)
File: /tmp/jl_GKwZG1
Mode: "w" (read-write)
HDUs: Num  Name  Type   
      1          Image  

julia> hdu
Error showing value of type ImageHDU{Float64, 2}:
ERROR: CFITSIO has encountered an error. Error code 107: tried to move past end of file

This PR allows us to throw an informative error

julia> hdu
Deleted HDU

julia> read(hdu)
ERROR: HDU doesn't exist, it has been deleted previously

The fits_assert_open calls are now replaced by assert_open which checks that the file is open as well as whether the hdu exists.

codecov[bot] commented 2 years ago

Codecov Report

Merging #176 (de975eb) into master (13256e1) will decrease coverage by 0.45%. The diff coverage is 89.74%.

:exclamation: Current head de975eb differs from pull request most recent head dd80f18. Consider uploading reports for the commit dd80f18 to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #176      +/-   ##
==========================================
- Coverage   91.41%   90.95%   -0.46%     
==========================================
  Files           5        5              
  Lines         617      663      +46     
==========================================
+ Hits          564      603      +39     
- Misses         53       60       +7     
Impacted Files Coverage Δ
src/table.jl 89.40% <60.00%> (-1.01%) :arrow_down:
src/FITSIO.jl 100.00% <100.00%> (ø)
src/fits.jl 96.38% <100.00%> (+0.55%) :arrow_up:
src/header.jl 84.97% <100.00%> (-0.92%) :arrow_down:
src/image.jl 95.71% <100.00%> (+0.15%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 13256e1...dd80f18. Read the comment docs.

jishnub commented 2 years ago

bump