merge: Throw S3 errors to prevent silent failures (resolves #697) (!1115)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1115

Closes #697

Approved-by: Marie <github@yuugi.dev>
Approved-by: dakkar <dakkar@thenautilus.net>
This commit is contained in:
dakkar 2025-06-14 09:54:50 +00:00
commit a9a7e4b9d0

View file

@ -164,7 +164,7 @@ export class DriveService {
try { try {
await this.videoProcessingService.webOptimizeVideo(path, type); await this.videoProcessingService.webOptimizeVideo(path, type);
} catch (err) { } catch (err) {
this.registerLogger.warn(`Video optimization failed: ${err instanceof Error ? err.message : String(err)}`, { error: err }); this.registerLogger.warn(`Video optimization failed: ${renderInlineError(err)}`);
} }
} }
@ -367,7 +367,7 @@ export class DriveService {
this.registerLogger.debug('web image not created (not an required image)'); this.registerLogger.debug('web image not created (not an required image)');
} }
} catch (err) { } catch (err) {
this.registerLogger.warn('web image not created (an error occurred)', err as Error); this.registerLogger.warn(`web image not created: ${renderInlineError(err)}`);
} }
} else { } else {
if (satisfyWebpublic) this.registerLogger.debug('web image not created (original satisfies webpublic)'); if (satisfyWebpublic) this.registerLogger.debug('web image not created (original satisfies webpublic)');
@ -386,7 +386,7 @@ export class DriveService {
thumbnail = await this.imageProcessingService.convertSharpToWebp(img, 498, 422); thumbnail = await this.imageProcessingService.convertSharpToWebp(img, 498, 422);
} }
} catch (err) { } catch (err) {
this.registerLogger.warn('thumbnail not created (an error occurred)', err as Error); this.registerLogger.warn(`Error creating thumbnail: ${renderInlineError(err)}`);
} }
// #endregion thumbnail // #endregion thumbnail
@ -420,27 +420,21 @@ export class DriveService {
); );
if (this.meta.objectStorageSetPublicRead) params.ACL = 'public-read'; if (this.meta.objectStorageSetPublicRead) params.ACL = 'public-read';
if (this.bunnyService.usingBunnyCDN(this.meta)) { try {
await this.bunnyService.upload(this.meta, key, stream).catch( if (this.bunnyService.usingBunnyCDN(this.meta)) {
err => { await this.bunnyService.upload(this.meta, key, stream);
this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err); } else {
}, const result = await this.s3Service.upload(this.meta, params);
); if ('Bucket' in result) { // CompleteMultipartUploadCommandOutput
} else { this.registerLogger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`);
await this.s3Service.upload(this.meta, params) } else { // AbortMultipartUploadCommandOutput
.then( this.registerLogger.error(`Upload Result Aborted: key = ${key}, filename = ${filename}`);
result => { throw new Error('S3 upload aborted');
if ('Bucket' in result) { // CompleteMultipartUploadCommandOutput }
this.registerLogger.debug(`Uploaded: ${result.Bucket}/${result.Key} => ${result.Location}`); }
} else { // AbortMultipartUploadCommandOutput } catch (err) {
this.registerLogger.error(`Upload Result Aborted: key = ${key}, filename = ${filename}`); this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}: ${renderInlineError(err)}`);
} throw err;
})
.catch(
err => {
this.registerLogger.error(`Upload Failed: key = ${key}, filename = ${filename}`, err);
},
);
} }
} }
@ -857,7 +851,7 @@ export class DriveService {
} }
} catch (err: any) { } catch (err: any) {
if (err.name === 'NoSuchKey') { if (err.name === 'NoSuchKey') {
this.deleteLogger.warn(`The object storage had no such key to delete: ${key}. Skipping this.`, err as Error); this.deleteLogger.warn(`The object storage had no such key to delete: ${key}. Skipping this.`);
return; return;
} else { } else {
throw new Error(`Failed to delete the file from the object storage with the given key: ${key}`, { throw new Error(`Failed to delete the file from the object storage with the given key: ${key}`, {