Skip to content

Commit

Permalink
Simplify error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Dec 8, 2024
1 parent d2ca1ec commit 06bfc2a
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions lib/modules/datasource/maven/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,18 @@ export async function downloadS3Protocol(
DeleteMarker,
}): Promise<MavenFetchResult> => {
if (DeleteMarker) {
logger.trace(
{ failedUrl: pkgUrl.toString() },
'Maven S3 lookup error: DeleteMarker encountered',
);
return Result.err({ type: 'not-found' });
}

if (!(Body instanceof Readable)) {
logger.debug(
{ failedUrl: pkgUrl.toString() },
'Maven S3 lookup error: unsupported Body type',
);
return Result.err({ type: 'unsupported-format' });
}

Expand All @@ -189,51 +197,31 @@ export async function downloadS3Protocol(
return Result.err(err);
}

if (err.name === 'CredentialsProviderError') {
return Result.err({ type: 'credentials-error' });
}

if (err.message === 'Region is missing') {
return Result.err({ type: 'missing-aws-region' });
}

if (isS3NotFound(err)) {
return Result.err({ type: 'not-found' });
}

return Result.err({ type: 'unknown', err });
})
.onError((err) => {
const failedUrl = pkgUrl.toString();

if (err.type === 'credentials-error') {
if (err.name === 'CredentialsProviderError') {
logger.debug(
{ failedUrl },
'Maven S3 lookup error: credentials provider error, check "AWS_ACCESS_KEY_ID" and "AWS_SECRET_ACCESS_KEY" variables',
);
return;
return Result.err({ type: 'credentials-error' });
}

if (err.type === 'missing-aws-region') {
if (err.message === 'Region is missing') {
logger.debug(
{ failedUrl },
'Maven S3 lookup error: missing region, check "AWS_REGION" variable',
);
return;
return Result.err({ type: 'missing-aws-region' });
}

if (err.type === 'not-found') {
if (isS3NotFound(err)) {
logger.trace({ failedUrl }, 'Maven S3 lookup error: object not found');
return;
return Result.err({ type: 'not-found' });
}

if (err.type === 'unknown') {
logger.debug(
{ failedUrl, err: err.err },
'Maven S3 lookup error: unknown error',
);
return;
}
logger.debug({ failedUrl, err }, 'Maven S3 lookup error: unknown error');
return Result.err({ type: 'unknown', err });
});
}

Expand Down

0 comments on commit 06bfc2a

Please sign in to comment.