From 2ba059a94588be961b2b08d4f4d75726c62cac4b Mon Sep 17 00:00:00 2001 From: Jordan Nelson Date: Tue, 23 Apr 2024 21:47:45 -0400 Subject: [PATCH 1/2] chore!: rename `StorageNotFoundException` --- .../types/exception/amplify_exception.dart | 2 +- .../storage/key_not_found_exception.dart | 19 ------------------- .../storage/not_found_exception.dart | 19 +++++++++++++++++++ .../lib/src/types/storage/storage_types.dart | 2 +- .../example/integration_test/copy_test.dart | 2 +- .../integration_test/get_properties_test.dart | 2 +- .../integration_test/get_url_test.dart | 2 +- .../integration_test/utils/object_exists.dart | 2 +- .../src/exception/s3_storage_exception.dart | 15 +++++++-------- .../service/task/s3_download_task.dart | 2 +- .../storage_s3_service_test.dart | 8 ++++---- .../task/s3_download_task_test.dart | 4 ++-- 12 files changed, 39 insertions(+), 40 deletions(-) delete mode 100644 packages/amplify_core/lib/src/types/exception/storage/key_not_found_exception.dart create mode 100644 packages/amplify_core/lib/src/types/exception/storage/not_found_exception.dart diff --git a/packages/amplify_core/lib/src/types/exception/amplify_exception.dart b/packages/amplify_core/lib/src/types/exception/amplify_exception.dart index fa5a7ea65a..aedc1c1e19 100644 --- a/packages/amplify_core/lib/src/types/exception/amplify_exception.dart +++ b/packages/amplify_core/lib/src/types/exception/amplify_exception.dart @@ -21,8 +21,8 @@ part 'network_exception.dart'; part 'push/push_notification_exception.dart'; part 'storage/access_denied_exception.dart'; part 'storage/http_status_exception.dart'; -part 'storage/key_not_found_exception.dart'; part 'storage/local_file_not_found_exception.dart'; +part 'storage/not_found_exception.dart'; part 'storage/operation_canceled_exception.dart'; part 'storage/path_validation_exception.dart'; part 'storage/storage_exception.dart'; diff --git a/packages/amplify_core/lib/src/types/exception/storage/key_not_found_exception.dart b/packages/amplify_core/lib/src/types/exception/storage/key_not_found_exception.dart deleted file mode 100644 index dad59fa791..0000000000 --- a/packages/amplify_core/lib/src/types/exception/storage/key_not_found_exception.dart +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -part of '../amplify_exception.dart'; - -/// {@template amplify_core.storage.key_not_found_exception} -/// Exception thrown when the key is not found in the storage service. -/// {@endtemplate} -class StorageKeyNotFoundException extends StorageException { - /// {@macro amplify_core.storage.key_not_found_exception} - const StorageKeyNotFoundException( - super.message, { - super.recoverySuggestion, - super.underlyingException, - }); - - @override - String get runtimeTypeName => 'StorageKeyNotFoundException'; -} diff --git a/packages/amplify_core/lib/src/types/exception/storage/not_found_exception.dart b/packages/amplify_core/lib/src/types/exception/storage/not_found_exception.dart new file mode 100644 index 0000000000..85add22bd9 --- /dev/null +++ b/packages/amplify_core/lib/src/types/exception/storage/not_found_exception.dart @@ -0,0 +1,19 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +part of '../amplify_exception.dart'; + +/// {@template amplify_core.storage.not_found_exception} +/// Exception thrown when the item is not found in the storage service. +/// {@endtemplate} +class StorageNotFoundException extends StorageException { + /// {@macro amplify_core.storage.not_found_exception} + const StorageNotFoundException( + super.message, { + super.recoverySuggestion, + super.underlyingException, + }); + + @override + String get runtimeTypeName => 'StorageNotFoundException'; +} diff --git a/packages/amplify_core/lib/src/types/storage/storage_types.dart b/packages/amplify_core/lib/src/types/storage/storage_types.dart index a7a1906689..9324a72683 100644 --- a/packages/amplify_core/lib/src/types/storage/storage_types.dart +++ b/packages/amplify_core/lib/src/types/storage/storage_types.dart @@ -6,7 +6,7 @@ export '../exception/amplify_exception.dart' StorageException, StorageAccessDeniedException, StorageHttpStatusException, - StorageKeyNotFoundException, + StorageNotFoundException, StorageLocalFileNotFoundException, StorageOperationCanceledException, NetworkException, diff --git a/packages/storage/amplify_storage_s3/example/integration_test/copy_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/copy_test.dart index c623c6b0dd..3fc05a80c8 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/copy_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/copy_test.dart @@ -114,7 +114,7 @@ void main() { source: const StoragePath.fromString('public/non-existent-path'), destination: const StoragePath.fromString('public/foo'), ).result, - throwsA(isA()), + throwsA(isA()), ); }); }); diff --git a/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart index 32f0e56eaf..37548397e8 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/get_properties_test.dart @@ -75,7 +75,7 @@ void main() { () => Amplify.Storage.getProperties( path: const StoragePath.fromString('public/not-existent-path'), ).result, - throwsA(isA()), + throwsA(isA()), ); }); }); diff --git a/packages/storage/amplify_storage_s3/example/integration_test/get_url_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/get_url_test.dart index 450f6bbbc7..f5f0cb7889 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/get_url_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/get_url_test.dart @@ -140,7 +140,7 @@ void main() { ), ), ).result, - throwsA(isA()), + throwsA(isA()), ); }); diff --git a/packages/storage/amplify_storage_s3/example/integration_test/utils/object_exists.dart b/packages/storage/amplify_storage_s3/example/integration_test/utils/object_exists.dart index 13d553aa80..c6e533f5ab 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/utils/object_exists.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/utils/object_exists.dart @@ -5,7 +5,7 @@ Future objectExists(StoragePath path) async { try { await Amplify.Storage.getProperties(path: path).result; return true; - } on StorageKeyNotFoundException { + } on StorageNotFoundException { return false; } } diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/exception/s3_storage_exception.dart b/packages/storage/amplify_storage_s3_dart/lib/src/exception/s3_storage_exception.dart index 520277ee82..05cd93d331 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/exception/s3_storage_exception.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/exception/s3_storage_exception.dart @@ -7,8 +7,7 @@ import 'package:amplify_storage_s3_dart/src/sdk/s3.dart' as s3; import 'package:meta/meta.dart'; import 'package:smithy/smithy.dart' as smithy; -const _keyNotFoundRecoveryMessage = - 'Ensure that correct StoragePath is provided.'; +const _notFoundRecoveryMessage = 'Ensure that correct StoragePath is provided.'; const _httpErrorRecoveryMessage = 'HTTP error returned from service, review the `underlyingException` for details.'; @@ -29,12 +28,12 @@ final accelerateEndpointUnusable = ConfigurationError( /// Extension of [s3.NoSuchKey] to add util methods. extension NoSuchKeyToStorageKeyNotFoundException on s3.NoSuchKey { - /// Creates a [StorageKeyNotFoundException] with the [s3.NoSuchKey] as the + /// Creates a [StorageNotFoundException] with the [s3.NoSuchKey] as the /// underlying exception. - StorageKeyNotFoundException toStorageKeyNotFoundException() { - return StorageKeyNotFoundException( + StorageNotFoundException toStorageNotFoundException() { + return StorageNotFoundException( 'Cannot find the item specified by the provided path.', - recoverySuggestion: _keyNotFoundRecoveryMessage, + recoverySuggestion: _notFoundRecoveryMessage, underlyingException: this, ); } @@ -64,9 +63,9 @@ extension UnknownSmithyHttpExceptionToStorageException underlyingException: this, ); } else if (statusCode == 404) { - return StorageKeyNotFoundException( + return StorageNotFoundException( 'Cannot find the item specified by the provided path.', - recoverySuggestion: _keyNotFoundRecoveryMessage, + recoverySuggestion: _notFoundRecoveryMessage, underlyingException: this, ); } else { diff --git a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_download_task.dart b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_download_task.dart index 3415447a3a..ae9e002481 100644 --- a/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_download_task.dart +++ b/packages/storage/amplify_storage_s3_dart/lib/src/storage_s3_service/service/task/s3_download_task.dart @@ -355,7 +355,7 @@ class S3DownloadTask { throw error.toStorageException(); } on s3.NoSuchKey catch (error) { // 404 error is wrapped by s3.NoSuchKey for getObject :/ - throw error.toStorageKeyNotFoundException(); + throw error.toStorageNotFoundException(); } on AWSHttpException catch (error) { throw error.toNetworkException(); } diff --git a/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/storage_s3_service_test.dart b/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/storage_s3_service_test.dart index 17107a3312..7b553bba62 100644 --- a/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/storage_s3_service_test.dart +++ b/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/storage_s3_service_test.dart @@ -465,7 +465,7 @@ void main() { }); test( - 'should throw StorageKeyNotFoundException when UnknownSmithyHttpException' + 'should throw StorageNotFoundException when UnknownSmithyHttpException' ' with status code 404 returned from service', () async { const testOptions = StorageGetPropertiesOptions(); const testUnknownException = UnknownSmithyHttpException( @@ -484,7 +484,7 @@ void main() { path: const StoragePath.fromString('a key'), options: testOptions, ), - throwsA(isA()), + throwsA(isA()), ); }); @@ -668,7 +668,7 @@ void main() { path: testPath, options: testOptions, ), - throwsA(isA()), + throwsA(isA()), ); final capturedRequest = verify( @@ -707,7 +707,7 @@ void main() { path: testPath, options: testOptions, ), - throwsA(isA()), + throwsA(isA()), ); final capturedRequest = verify( diff --git a/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/task/s3_download_task_test.dart b/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/task/s3_download_task_test.dart index ae1ea95f3d..950b88d854 100644 --- a/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/task/s3_download_task_test.dart +++ b/packages/storage/amplify_storage_s3_dart/test/storage_s3_service/task/s3_download_task_test.dart @@ -430,9 +430,9 @@ void main() { exceptionTypeMatcher: isA(), ), DownloadTaskExceptionConversionTestItem( - description: 'it should complete with a StorageKeyNotFoundException', + description: 'it should complete with a StorageNotFoundException', originalException: NoSuchKey(), - exceptionTypeMatcher: isA(), + exceptionTypeMatcher: isA(), ), DownloadTaskExceptionConversionTestItem( description: 'it should complete with a NetworkException', From daaf3b539ae3c385bad4b56774f75179ff1c0c53 Mon Sep 17 00:00:00 2001 From: Jordan Nelson Date: Tue, 23 Apr 2024 21:52:43 -0400 Subject: [PATCH 2/2] chore: remove skip test for web --- .../example/integration_test/upload_file_test.dart | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/storage/amplify_storage_s3/example/integration_test/upload_file_test.dart b/packages/storage/amplify_storage_s3/example/integration_test/upload_file_test.dart index 10c87d0148..8c089a082f 100644 --- a/packages/storage/amplify_storage_s3/example/integration_test/upload_file_test.dart +++ b/packages/storage/amplify_storage_s3/example/integration_test/upload_file_test.dart @@ -4,7 +4,6 @@ import 'package:amplify_core/amplify_core.dart'; import 'package:amplify_storage_s3/amplify_storage_s3.dart'; import 'package:amplify_storage_s3_example/amplifyconfiguration.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; @@ -40,8 +39,6 @@ void main() { ).result; expect(downloadResult.bytes, data); }, - // TODO(Jordan-Nelson): Resolve bug with `AWSFile.fromData` on web. - skip: kIsWeb, ); testWidgets('from path', (_) async {