JuliaIO / HDF5.jl

Save and load data in the HDF5 file format from Julia
https://juliaio.github.io/HDF5.jl
MIT License
390 stars 143 forks source link

fix error message on write_attribute #951

Closed simonbyrne closed 2 years ago

simonbyrne commented 2 years ago

the error message was calling h5a_get_name on an object, not an attribute.

Previously:

julia> using HDF5

julia> filename = tempname();

julia> f = h5open(filename, "w");

julia> write_attribute(f, "a", 2)

julia> write_attribute(f, "a", 3)
ERROR: HDF5.API.H5Error: Error getting attribute name
libhdf5 Stacktrace:
 [1] H5Aget_name: Invalid arguments to routine/Inappropriate type
     not an attribute
Stacktrace:
  [1] macro expansion
    @ ~/src/HDF5.jl/src/api/error.jl:18 [inlined]
  [2] h5a_get_name(attr_id::HDF5.File, buf_size::Int64, buf::Ptr{Nothing})
    @ HDF5.API ~/src/HDF5.jl/src/api/functions.jl:207
  [3] h5a_get_name(attr_id::HDF5.File)
    @ HDF5.API ~/src/HDF5.jl/src/api/helpers.jl:38
  [4] macro expansion
    @ ~/src/HDF5.jl/src/api/error.jl:18 [inlined]
  [5] h5a_create(loc_id::HDF5.File, pathname::String, type_id::HDF5.Datatype, space_id::HDF5.Dataspace, acpl_id::HDF5.AttributeCreateProperties, aapl_id::Int64)
    @ HDF5.API ~/src/HDF5.jl/src/api/functions.jl:119
  [6] create_attribute
    @ ~/src/HDF5.jl/src/attributes.jl:101 [inlined]
  [7] create_attribute(parent::HDF5.File, name::String, data::Int64; pv::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ HDF5 ~/src/HDF5.jl/src/attributes.jl:94
  [8] create_attribute
    @ ~/src/HDF5.jl/src/attributes.jl:91 [inlined]
  [9] write_attribute(parent::HDF5.File, name::String, data::Int64; pv::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ HDF5 ~/src/HDF5.jl/src/attributes.jl:130
 [10] write_attribute(parent::HDF5.File, name::String, data::Int64)
    @ HDF5 ~/src/HDF5.jl/src/attributes.jl:130
 [11] top-level scope
    @ REPL[8]:1

Now:

julia> using HDF5

julia> filename = tempname();

julia> f = h5open(filename, "w");

julia> write_attribute(f, "a", 2)

julia> write_attribute(f, "a", 3)
ERROR: HDF5.API.H5Error: Error creating attribute a for object /
libhdf5 Stacktrace:
 [1] H5A__create: Attribute/Object already exists
     attribute already exists
  ⋮
 [5] H5Acreate2: Attribute/Unable to initialize object
     unable to create attribute
Stacktrace:
 [1] macro expansion
   @ ~/src/HDF5.jl/src/api/error.jl:18 [inlined]
 [2] h5a_create(loc_id::HDF5.File, attr_name::String, type_id::HDF5.Datatype, space_id::HDF5.Dataspace, acpl_id::HDF5.AttributeCreateProperties, aapl_id::Int64)
   @ HDF5.API ~/src/HDF5.jl/src/api/functions.jl:119
 [3] create_attribute
   @ ~/src/HDF5.jl/src/attributes.jl:101 [inlined]
 [4] create_attribute(parent::HDF5.File, name::String, data::Int64; pv::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ HDF5 ~/src/HDF5.jl/src/attributes.jl:94
 [5] create_attribute
   @ ~/src/HDF5.jl/src/attributes.jl:91 [inlined]
 [6] write_attribute(parent::HDF5.File, name::String, data::Int64; pv::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ HDF5 ~/src/HDF5.jl/src/attributes.jl:130
 [7] write_attribute(parent::HDF5.File, name::String, data::Int64)
   @ HDF5 ~/src/HDF5.jl/src/attributes.jl:130
 [8] top-level scope
   @ REPL[5]:1