Skip to content

Commit d0b7c29

Browse files
committed
Wrap zarr-java S3 failures in StoreAccessException
S3Store reported S3 errors as the AWS SDK's unchecked SdkException, which escaped the StoreException-only catch and surfaced unhandled in Fiji. Catch both exception types now and drop the MockedConstruction from storeAccessErrorIsReportedToErrorHandler so ZARR_JAVA exercises the same real path as N5.
1 parent 9e73115 commit d0b7c29

2 files changed

Lines changed: 7 additions & 30 deletions

File tree

ome-zarr-fiji-ui/src/test/java/ome/zarr/fijiui/open/ZarrOpenActionsTest.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import static org.mockito.Mockito.mockStatic;
4343
import static org.mockito.Mockito.times;
4444
import static org.mockito.Mockito.verify;
45-
import static org.mockito.Mockito.when;
4645
import static ome.zarr.ZarrTestUtils.IMAGE_NAME;
4746

4847
import net.imagej.Dataset;
@@ -95,8 +94,6 @@
9594
import ij.ImagePlus;
9695
import ome.zarr.fijiui.settings.UserScriptSettings;
9796
import ome.zarr.fiji.Pyramidal;
98-
import ome.zarr.zarrjava.ZarrJavaPyramidBackend;
99-
import ome.zarr.imglib2.exceptions.StoreAccessException;
10097
import ome.zarr.imglib2.PyramidBackend;
10198
import ome.zarr.imglib2.PyramidContents;
10299
import ome.zarr.fiji.open.ZarrOpener;
@@ -685,29 +682,10 @@ void storeAccessErrorIsReportedToErrorHandler( final ZarrReaderBackend backend )
685682
final ZarrOpeningSettings settings = new ZarrOpeningSettings();
686683
settings.setReaderBackend( backend );
687684

688-
if ( backend == ZarrReaderBackend.ZARR_JAVA )
689-
{
690-
try (MockedConstruction< ZarrJavaPyramidBackend > mock = mockConstruction(
691-
ZarrJavaPyramidBackend.class,
692-
( mockBackend, ctx ) -> when( mockBackend.load( any() ) )
693-
.thenThrow( new StoreAccessException( uri.toString(),
694-
new RuntimeException( "Access Denied (403)" ) ) ) ))
695-
{
696-
final ZarrOpenActions actions = new ZarrOpenActions( uri, context, settings, capturedError::set );
697-
assertDoesNotThrow( () -> {
698-
actions.openIJWithImage();
699-
} );
700-
assertEquals( 1, mock.constructed().size(), "Expected exactly one ZarrJavaPyramidBackend to be constructed" );
701-
}
702-
}
703-
else
704-
{
705-
// N5 backend throws N5Exception.N5IOException immediately (local failure, no network needed)
706-
final ZarrOpenActions actions = new ZarrOpenActions( uri, context, settings, capturedError::set );
707-
assertDoesNotThrow( () -> {
708-
actions.openIJWithImage();
709-
} );
710-
}
685+
final ZarrOpenActions actions = new ZarrOpenActions( uri, context, settings, capturedError::set );
686+
assertDoesNotThrow( () -> {
687+
actions.openIJWithImage();
688+
}, "Store access failures must not escape openIJWithImage() for backend " + backend );
711689

712690
assertNotNull( capturedError.get(), "Error handler should have been called for backend " + backend );
713691
assertTrue( capturedError.get().contains( uri.toString() ),

ome-zarr-zarrjava/src/main/java/ome/zarr/zarrjava/ZarrJavaPyramidBackend.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
6262
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
6363
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
64+
import software.amazon.awssdk.core.exception.SdkException;
6465
import software.amazon.awssdk.regions.Region;
6566
import software.amazon.awssdk.services.s3.S3Client;
6667

@@ -260,11 +261,9 @@ else if ( "s3".equalsIgnoreCase( scheme ) )
260261
{
261262
return openMultiscaleImageFromHandle( store.resolve() );
262263
}
263-
catch ( StoreException e )
264+
catch ( StoreException | SdkException e )
264265
{
265-
// Store-level failure (e.g., S3 auth failure, missing bucket, network
266-
// error) before we could reach the dataset. Wrap in a backend-agnostic
267-
// exception.
266+
// Store-level failures. Wrap them in a backend-agnostic exception.
268267
throw new StoreAccessException( inputUri.toString(), e );
269268
}
270269
}

0 commit comments

Comments
 (0)