diff --git a/packages/core/src/storages/disk-storage.ts b/packages/core/src/storages/disk-storage.ts index 7f6ae298..a6bc1417 100644 --- a/packages/core/src/storages/disk-storage.ts +++ b/packages/core/src/storages/disk-storage.ts @@ -64,10 +64,12 @@ export class DiskStorage extends BaseStorage { const metaConfig = { ...config, ...config.metaStorageConfig }; this.meta = new LocalMetaStorage(metaConfig); } - this.accessCheck().catch(err => { - this.isReady = false; - this.logger.error('[error]: Could not write to directory: %O', err); - }); + this.isReady = false; + this.accessCheck() + .then(() => (this.isReady = true)) + .catch(err => { + this.logger.error('Storage access check failed: %O', err); + }); } normalizeError(err: Error): HttpError { diff --git a/packages/core/src/storages/local-meta-storage.ts b/packages/core/src/storages/local-meta-storage.ts index 90236602..10d11045 100644 --- a/packages/core/src/storages/local-meta-storage.ts +++ b/packages/core/src/storages/local-meta-storage.ts @@ -21,7 +21,7 @@ export class LocalMetaStorage extends MetaStorage { super(config); this.directory = (config?.directory || join(tmpdir(), 'uploadx_meta')).replace(/\\/g, '/'); this.accessCheck().catch(err => { - this.logger.error('[error]: Could not write to directory: %O', err); + this.logger.error('Metadata storage access check failed: %O', err); }); } diff --git a/packages/core/src/utils/fs.ts b/packages/core/src/utils/fs.ts index 72673022..0f0afdda 100644 --- a/packages/core/src/utils/fs.ts +++ b/packages/core/src/utils/fs.ts @@ -21,7 +21,11 @@ export async function ensureFile(path: string, overwrite = false): Promise { - await fsp.mkdir(dir, { recursive: true }); + try { + await fsp.mkdir(dir, { recursive: true }); + } catch { + throw new Error(`Directory is not accessible: ${dir}`); + } } /** diff --git a/packages/gcs/src/gcs-storage.ts b/packages/gcs/src/gcs-storage.ts index a151f573..e9006958 100644 --- a/packages/gcs/src/gcs-storage.ts +++ b/packages/gcs/src/gcs-storage.ts @@ -122,10 +122,10 @@ export class GCStorage extends BaseStorage { config.scopes ||= GCSConfig.authScopes; this.authClient = new GoogleAuth(config); - this.accessCheck().catch((err: ClientError) => { - this.isReady = false; - this.logger.error('Unable to open bucket: %O', err); - }); + this.isReady = false; + this.accessCheck() + .then(() => (this.isReady = true)) + .catch(err => this.logger.error('Storage access check failed: %O', err)); } normalizeError(error: ClientError): HttpError { diff --git a/packages/s3/src/s3-storage.ts b/packages/s3/src/s3-storage.ts index 88c719d1..535b5c53 100644 --- a/packages/s3/src/s3-storage.ts +++ b/packages/s3/src/s3-storage.ts @@ -146,10 +146,10 @@ export class S3Storage extends BaseStorage { ? new LocalMetaStorage(metaConfig) : new S3MetaStorage(metaConfig); } - this.accessCheck().catch((err: AWSError) => { - this.isReady = false; - this.logger.error('Unable to open bucket: %O', err); - }); + this.isReady = false; + this.accessCheck() + .then(() => (this.isReady = true)) + .catch(err => this.logger.error('Storage access check failed: %O', err)); } normalizeError(error: AWSError): HttpError {