silx-kit / h5web

React components for data visualization and exploration
https://h5web.panosc.eu/
MIT License
167 stars 17 forks source link

Propage h5wasm errors to viewer #1570

Closed axelboc closed 4 months ago

axelboc commented 5 months ago

Describe the bug

When h5wasm throws an error internally, for instance when reading a compressed dataset without the appropriate plugin, the error appears in the console but is not propagated to the viewer.

For compressed datasets, if we didn't throw our own error when the required compression plugins aren't available, we might not even realise the problem, since the visualization would most likely continue to work. In other cases, like with this bug report that was encountered on myHDF5, the h5wasm error causes the viewer to throw another, completely unrelated error further down the line, which can be confusing.

To Reproduce

  1. Comment out one of the plugins in apps/demo/src/h5wasm/plugin-utils.ts (e.g. Zstandard) and silence the TS error.
  2. Comment out the line that throws the "plugin not supported" error in packages/h5wasm/src/h5wasm-api.ts (replace with early return).
  3. Start the demo and visit http://localhost:5173/h5wasm?url=https%3A%2F%2Fwww.silx.org%2Fpub%2Fh5web%2Ffilters.h5
  4. Select the dataset matching the compression plugin that you disabled (e.g. zstd).
  5. 👉 The Line visualization appears to work but there is an error in the browser console.

Expected behaviour

When h5wasm throws an error, this error should be propagated to the viewer and trigger the visualization area's error boundary.

axelboc commented 4 months ago

Apparently, exception handling is disabled in Emscripten by default. So it might simply be a matter of compiling h5wasm with flag -fwasm-exceptions.

bmaranville commented 4 months ago

By default, the HDF5 library error handler function prints to the error stream for every error. This is what is ending up in the users' console. That error handler function can be overridden, but it would require writing a new error handler function in C, and setting that as the default. There don't seem to be a lot of examples of custom error handler functions.

It's possible that the C++ API for for HDF5 has exception handling in it already - but migrating to that API from the C API would also be some work.

bmaranville commented 4 months ago

There is a PR brewing for raising exceptions in h5wasm here: https://github.com/usnistgov/h5wasm/pull/68 I still have to write some tests, but it seems to work as expected.

axelboc commented 4 months ago

Fantastic!! Thanks for looking into this 💯

bmaranville commented 4 months ago

Opt-in to throwing error handler is available new release https://github.com/usnistgov/h5wasm/releases/tag/v0.7.2