Resolves allen-cell-animated/website-3d-cell-viewer#183: makes error handling when loading volumes more consistent, stricter, and more informative.
Adds a new error type:VolumeLoadError. Most (hopefully all) errors that can happen within loaders should now be caught and re-thrown wrapped in this error type, with a more specific and useful error message than the inner error. This error also holds a type field which announces the error's membership in one of a few broad categories (e.g. "no data found," "metadata invalid") so that we can give the user specific guidance about what to do next (e.g. "check that the URL is right," "try regenerating your metadata," "open an issue ticket and tell us to fix our viewer").
Adds a new package: serialize-error allows us to safely send errors from the volume loader worker to the main thread while preserving prototypes and custom properties, ensuring we don't accidentally try to send a buffer or a function or a reference cycle, etc.
Makes some tweaks to volume loading: while I was trying to cover all our error-handling bases, I made some tweaks to the actual behavior of data loading:
More metadata validation.OMEZarrLoader and TiffLoader now do some basic sanity checks to their metadata, rather than trusting that they're complete and well-typed from the start. These checks, naturally, throw a VolumeLoadError on fail, with type INVALID_METADATA and a message describing exactly which field was missing. This helps us avoid failing later with a more cryptic error message, e.g. "cannot read properties of undefined."
Make omero metadata optional.omero is a metadata record specified by OME-Zarr which provides us with volume and channel names. While I was writing code to validate zarr metadata, I realized there's no great reason to fail if it isn't present - we can provide reasonable defaults for anything it gives us. So I added code to provide reasonable defaults for anything it might give us.
Review time: medium
Resolves allen-cell-animated/website-3d-cell-viewer#183: makes error handling when loading volumes more consistent, stricter, and more informative.
Adds a new error type:
VolumeLoadError
. Most (hopefully all) errors that can happen within loaders should now be caught and re-thrown wrapped in this error type, with a more specific and useful error message than the inner error. This error also holds atype
field which announces the error's membership in one of a few broad categories (e.g. "no data found," "metadata invalid") so that we can give the user specific guidance about what to do next (e.g. "check that the URL is right," "try regenerating your metadata," "open an issue ticket and tell us to fix our viewer").Adds a new package: serialize-error allows us to safely send errors from the volume loader worker to the main thread while preserving prototypes and custom properties, ensuring we don't accidentally try to send a buffer or a function or a reference cycle, etc.
Makes some tweaks to volume loading: while I was trying to cover all our error-handling bases, I made some tweaks to the actual behavior of data loading:
OMEZarrLoader
andTiffLoader
now do some basic sanity checks to their metadata, rather than trusting that they're complete and well-typed from the start. These checks, naturally, throw aVolumeLoadError
on fail, with typeINVALID_METADATA
and a message describing exactly which field was missing. This helps us avoid failing later with a more cryptic error message, e.g. "cannot read properties of undefined."omero
metadata optional.omero
is a metadata record specified by OME-Zarr which provides us with volume and channel names. While I was writing code to validate zarr metadata, I realized there's no great reason to fail if it isn't present - we can provide reasonable defaults for anything it gives us. So I added code to provide reasonable defaults for anything it might give us.