Skip to content

Commit 721a434

Browse files
committed
warn user if 403 error when no credentials are set
1 parent aa436fc commit 721a434

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

build-tests/rush-amazon-s3-build-cache-plugin-integration-test/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In this folder run `docker-compose down`
1717
rushx read-s3-object
1818
```
1919

20-
# Test retries
20+
# Testing retries
2121

2222
To test that requests can be retried start the proxy server which will fail every second request:
2323

rush-plugins/rush-amazon-s3-build-cache-plugin/src/AmazonS3Client.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ export class AmazonS3Client {
152152
) {
153153
// unauthorized due to not providing credentials,
154154
// silence error for better DX when e.g. running locally without credentials
155+
this._writeWarningLine(
156+
`No credentials found and received a ${response.status}`,
157+
' response code from the cloud storage.',
158+
' Maybe run rush update-cloud-credentials',
159+
' or set the RUSH_BUILD_CACHE_CREDENTIAL env'
160+
);
155161
return {
156162
hasNetworkError: false,
157163
response: undefined
@@ -193,7 +199,16 @@ export class AmazonS3Client {
193199
try {
194200
this._terminal.writeDebugLine(...messageParts);
195201
} catch (err) {
196-
//
202+
// ignore error
203+
}
204+
}
205+
206+
private _writeWarningLine(...messageParts: (string | IColorableSequence)[]): void {
207+
// if the terminal has been closed then don't bother sending a warning message
208+
try {
209+
this._terminal.writeWarningLine(...messageParts);
210+
} catch (err) {
211+
// ignore error
197212
}
198213
}
199214

rush-plugins/rush-amazon-s3-build-cache-plugin/src/test/AmazonS3Client.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,15 @@ describe(AmazonS3Client.name, () => {
452452

453453
for (const code of [400, 401, 403]) {
454454
it(`Handles missing credentials object when ${code}`, async () => {
455-
const result: Buffer | undefined = await makeGetRequestAsync(
455+
let warningSpy: jest.SpyInstance<any, unknown[]> | undefined;
456+
const result: Buffer | undefined = await makeS3ClientRequestAsync(
456457
undefined,
457458
DUMMY_OPTIONS,
458-
'abc123',
459+
async (s3Client) => {
460+
(s3Client as any)._writeWarningLine = () => {};
461+
warningSpy = jest.spyOn(s3Client as any, '_writeWarningLine');
462+
return await s3Client.getObjectAsync('abc123');
463+
},
459464
{
460465
responseInit: {
461466
status: code,
@@ -467,6 +472,13 @@ describe(AmazonS3Client.name, () => {
467472
}
468473
);
469474
expect(result).toBeUndefined();
475+
expect(warningSpy).toHaveBeenNthCalledWith(
476+
1,
477+
`No credentials found and received a ${code}`,
478+
' response code from the cloud storage.',
479+
' Maybe run rush update-cloud-credentials',
480+
' or set the RUSH_BUILD_CACHE_CREDENTIAL env'
481+
);
470482
});
471483
}
472484
});

0 commit comments

Comments
 (0)