ome / omero-cli-zarr

https://pypi.org/project/omero-cli-zarr/
GNU General Public License v2.0
15 stars 10 forks source link

Improve reporting the "export image" error #89

Open khaledk2 opened 2 years ago

khaledk2 commented 2 years ago

When I export an image using a specific id for the first time, it works fine: omero zarr export Image:xx

But if I try to export it again using the same id, I get the error message at the end of this issue description.

Will mentioned that this is expected as Zarr won't overwrite the existing data that the user creates with the first export. The user can either delete before repeating or output to a different directory.

I think we need a more user-friendly message to inform the user explicitly about this rather than throwing an exception.

Traceback (most recent call last): File "/home/khaled/anaconda3/envs/ome_ngff/bin/omero", line 8, in sys.exit(main()) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero/main.py", line 125, in main rv = omero.cli.argv() File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero/cli.py", line 1784, in argv cli.invoke(args[1:]) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero/cli.py", line 1222, in invoke stop = self.onecmd(line, previous_args) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero/cli.py", line 1299, in onecmd self.execute(line, previous_args) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero/cli.py", line 1381, in execute args.func(args) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero_zarr/cli.py", line 65, in _wrapper return func(self, args, kwargs) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero_zarr/cli.py", line 260, in export image_to_zarr(image, args) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero_zarr/raw_pixels.py", line 27, in image_to_zarr n_levels, axes = add_image(image, root, cache_dir=cache_dir) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero_zarr/raw_pixels.py", line 82, in add_image return add_raw_image( File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/omero_zarr/raw_pixels.py", line 155, in add_raw_image parent.create( File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/zarr/hierarchy.py", line 891, in create return self._write_op(self._create_nosync, name, kwargs) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/zarr/hierarchy.py", line 661, in _write_op return f(args, **kwargs) File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/zarr/hierarchy.py", line 897, in _create_nosync return create(store=self._store, path=path, chunk_store=self._chunk_store, File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/zarr/creation.py", line 138, in create init_array(store, shape=shape, chunks=chunks, dtype=dtype, compressor=compressor, File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/zarr/storage.py", line 353, in init_array _init_array_metadata(store, shape=shape, chunks=chunks, dtype=dtype, File "/home/khaled/anaconda3/envs/ome_ngff/lib/python3.9/site-packages/zarr/storage.py", line 384, in _init_array_metadata raise ContainsArrayError(path) zarr.errors.ContainsArrayError: path '0' contains an array

sbesson commented 2 years ago

I suspect the OMERO path needs to check the existence of of the target Zarr folder and report an informative message to the user to what is implemented in the bioformats2raw export path

https://github.com/ome/omero-cli-zarr/blob/2d0a62b7e266e4d0d8874fddd33fcc55f6b111b6/src/omero_zarr/cli.py#L288-L291