From c82787bc1780d4b23c19380a5c52bc91a99a235a Mon Sep 17 00:00:00 2001 From: Anton SHEPILOV Date: Thu, 19 Dec 2024 19:02:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8FAdded=20file=20path=20to=20al?= =?UTF-8?q?l=20storage=20exceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/platform/services/storage/exceptions.ts | 12 ++++++++++-- .../services/storage/oneof-storage-strategy.ts | 9 ++++++--- .../platform/services/storage/storage-service.ts | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tdrive/backend/node/src/core/platform/services/storage/exceptions.ts b/tdrive/backend/node/src/core/platform/services/storage/exceptions.ts index f4fb0f7b..72d59c8d 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/exceptions.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/exceptions.ts @@ -1,2 +1,10 @@ -export class FileNotFountException extends Error {} -export class WriteFileException extends Error {} +export class FileNotFountException extends Error { + constructor(readonly path: string, details: string) { + super(details); + } +} +export class WriteFileException extends Error { + constructor(readonly path: string, details: string) { + super(details); + } +} diff --git a/tdrive/backend/node/src/core/platform/services/storage/oneof-storage-strategy.ts b/tdrive/backend/node/src/core/platform/services/storage/oneof-storage-strategy.ts index e366bedd..0e44b3a8 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/oneof-storage-strategy.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/oneof-storage-strategy.ts @@ -77,6 +77,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI { logger.error( new OneOfStorageWriteOneFailedException( storageId, + path, `Error writing to storage ${storageId}`, (result as PromiseRejectedResult).reason, ), @@ -85,7 +86,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI { } }); if (errorsCount === this.storages.length) { - throw new WriteFileException(`Write ${path} failed for all storages`); + throw new WriteFileException(path, `Write ${path} failed for all storages`); } const successResult = writeResults.filter( @@ -111,13 +112,14 @@ export class OneOfStorageStrategy implements StorageConnectorAPI { logger.error( new OneOfStorageReadOneFailedException( storage.getId(), + path, `Reading ${path} from storage ${storage} failed.`, err, ), ); } } - throw new FileNotFountException(`Error reading ${path}`); + throw new FileNotFountException(path, `Error reading ${path}`); }; /** @@ -135,6 +137,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI { } catch (e) { throw new OneOfStorageReadOneFailedException( storage.getId(), + path, `Reading ${path} from storage ${storage} failed.`, e, ); @@ -159,7 +162,7 @@ export class OneOfStorageStrategy implements StorageConnectorAPI { * Throw when read from one of the storages is filed. */ class StorageException extends Error { - constructor(readonly storageId: string, details: string, error: Error) { + constructor(readonly storageId: string, readonly path: string, details: string, error: Error) { super(details, error); } } diff --git a/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts b/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts index 4eaea4ba..b57d1807 100644 --- a/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts +++ b/tdrive/backend/node/src/core/platform/services/storage/storage-service.ts @@ -104,7 +104,7 @@ export default class StorageService extends TdriveService implements async read(path: string, options?: ReadOptions): Promise { if (!(await this.exists(path, options))) { - throw new FileNotFountException(); + throw new FileNotFountException(path, "File doesn't exist"); } try { // eslint-disable-next-line @typescript-eslint/no-this-alias