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

adding h5e_get_auto wrapper for error handling manipulation #150

Closed
getzdan opened this issue Sep 9, 2014 · 5 comments
Closed

adding h5e_get_auto wrapper for error handling manipulation #150

getzdan opened this issue Sep 9, 2014 · 5 comments

Comments

@getzdan
Copy link

getzdan commented Sep 9, 2014

HDF5 outputs a lot of DIAG messages. they can be turned off with:

   HDF5.h5e_set_auto(HDF5.H5E_DEFAULT, C_NULL, C_NULL)

nice, but if one wants to turn DIAG back on she needs the original error handlers.
to get those you can use h5e_get_auto. which can be wrapped in HDF5 with the following change:

   diff --git a/src/plain.jl b/src/plain.jl
   index 7c58932..ee857a9 100644
   --- a/src/plain.jl
   +++ b/src/plain.jl
         (:h5d_write, :H5Dwrite, Herr, (Hid, Hid, Hid, Hid, Hid, Ptr{Void}), (:dataset_id, :mem_type_id, :mem_space_id, :file_space_id
   +     (:h5e_get_auto, :H5Eget_auto2, Herr, (Hid, Ptr{Ptr{Void}},Ptr{Ptr{Void}}), (:estack_id, :func, :client_data), "Error getting 
         (:h5e_set_auto, :H5Eset_auto2, Herr, (Hid, Ptr{Void}, Ptr{Void}), (:estack_id, :func, :client_data), "Error setting error rep

then, turn off/on messages can be accomplished with:

   hdf5errorfunc = Array(Ptr{Void},1)
   hdf5errorprivdata = Array(Ptr{Void},1)
   # turn off messages
   res = HDF5.h5e_get_auto(HDF5.H5E_DEFAULT, hdf5errorfunc, hdf5errorprivdata)
   HDF5.h5e_set_auto(HDF5.H5E_DEFAULT, C_NULL, C_NULL)
   # turn on messages
   HDF5.h5e_set_auto(HDF5.H5E_DEFAULT, hdf5errorfunc[1], hdf5errorprivdata[1])

have little experience with turning things into pull requests, but can do so if I get a pull-request request.

@timholy
Copy link
Member

timholy commented Sep 9, 2014

Can you give us an example of the kind of error messages you want to suppress, and what the resulting output would be? I agree that the messages are long and ugly, but no messages would make debugging harder.

@getzdan
Copy link
Author

getzdan commented Sep 9, 2014

When trying to open a non-existent file for example:

In  [12]: h5f = h5open("/ptmp/data/asdf.h5")
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 3059767040:
  #000: ../../../src/H5F.c line 858 in H5Fis_hdf5(): unable to open file
    major: Low-level I/O
    minor: Unable to initialize object
  #001: ../../../src/H5FD.c line 987 in H5FD_open(): open failed
    major: Virtual File Layer
    minor: Unable to initialize object
  #002: ../../../src/H5FDsec2.c line 343 in H5FD_sec2_open(): unable to open file: name = '/ptmp/data/asdf.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0
    major: File accessibilty
    minor: Unable to open file

Out [12]: ERROR: Cannot access file /ptmp/data/asdf.h5
while loading In[12], in expression starting on line 1
 in h5f_is_hdf5 at /home/dan/.julia/v0.4/HDF5/src/plain.jl:1944
 in h5open at /home/dan/.julia/v0.4/HDF5/src/plain.jl:513
 in h5open at /home/dan/.julia/v0.4/HDF5/src/plain.jl:523 (repeats 2 times)

The usefulness for debugging is exactly the reason I wanted an on/off ability for message suppression.

@timholy
Copy link
Member

timholy commented Sep 9, 2014

Are you proposing off by default, or on by default? We would also need a more convenient way of turning them back on. (Something where the user doesn't effectively have to know the libhdf5 API.)

As long as what you're proposing is merely an expansion of capabilities, then sure, it would be worth merging a PR.

@getzdan
Copy link
Author

getzdan commented Sep 9, 2014

"on" by default is fine. a couple of functions for on/off toggling would be nice, especially in try/catch/finally blocks which are expected to generate errors occasionally.

currently, my only change was a one-liner in plain.jl (see above) and toggling is then possible (as described). a higher level API for this feature is a good idea.

@kleinhenz
Copy link
Contributor

closed via #677.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants