Skip to content

Commit 603b75d

Browse files
author
Kamil Sobol
authored
Classify pointing client config generator at metadata-less stack as user error (#2024)
1 parent 98673b0 commit 603b75d

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

.changeset/poor-owls-listen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/client-config': patch
3+
---
4+
5+
Classify pointing client config generator at metadata-less stack as user error

packages/client-config/src/unified_client_config_generator.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,39 @@ void describe('UnifiedClientConfigGenerator', () => {
449449
);
450450
});
451451

452+
void it('throws user error if the stack is missing metadata', async () => {
453+
const outputRetrieval = mock.fn(() => {
454+
throw new BackendOutputClientError(
455+
BackendOutputClientErrorType.METADATA_RETRIEVAL_ERROR,
456+
'Stack template metadata is not a string'
457+
);
458+
});
459+
const modelSchemaAdapter = new ModelIntrospectionSchemaAdapter(
460+
stubClientProvider
461+
);
462+
463+
const configContributors = new ClientConfigContributorFactory(
464+
modelSchemaAdapter
465+
).getContributors('1.1');
466+
467+
const clientConfigGenerator = new UnifiedClientConfigGenerator(
468+
outputRetrieval,
469+
configContributors
470+
);
471+
472+
await assert.rejects(
473+
() => clientConfigGenerator.generateClientConfig(),
474+
(error: AmplifyUserError) => {
475+
assert.strictEqual(
476+
error.message,
477+
'Stack was not created with Amplify.'
478+
);
479+
assert.ok(error.resolution);
480+
return true;
481+
}
482+
);
483+
});
484+
452485
void it('throws user error if credentials are expired when getting backend outputs', async () => {
453486
const outputRetrieval = mock.fn(() => {
454487
throw new BackendOutputClientError(

packages/client-config/src/unified_client_config_generator.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ export class UnifiedClientConfigGenerator implements ClientConfigGenerator {
6666
error
6767
);
6868
}
69+
if (
70+
error instanceof BackendOutputClientError &&
71+
error.code === BackendOutputClientErrorType.METADATA_RETRIEVAL_ERROR
72+
) {
73+
throw new AmplifyUserError(
74+
'NonAmplifyStackError',
75+
{
76+
message: 'Stack was not created with Amplify.',
77+
resolution:
78+
'Ensure the CloudFormation stack ID references a main stack created with Amplify, then re-run this command.',
79+
},
80+
error
81+
);
82+
}
6983
if (
7084
error instanceof BackendOutputClientError &&
7185
error.code === BackendOutputClientErrorType.CREDENTIALS_ERROR

0 commit comments

Comments
 (0)