Skip to content

Commit

Permalink
Classify pointing client config generator at metadata-less stack as u…
Browse files Browse the repository at this point in the history
…ser error (#2024)
  • Loading branch information
sobolk authored Sep 18, 2024
1 parent 98673b0 commit 603b75d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-owls-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/client-config': patch
---

Classify pointing client config generator at metadata-less stack as user error
33 changes: 33 additions & 0 deletions packages/client-config/src/unified_client_config_generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,39 @@ void describe('UnifiedClientConfigGenerator', () => {
);
});

void it('throws user error if the stack is missing metadata', async () => {
const outputRetrieval = mock.fn(() => {
throw new BackendOutputClientError(
BackendOutputClientErrorType.METADATA_RETRIEVAL_ERROR,
'Stack template metadata is not a string'
);
});
const modelSchemaAdapter = new ModelIntrospectionSchemaAdapter(
stubClientProvider
);

const configContributors = new ClientConfigContributorFactory(
modelSchemaAdapter
).getContributors('1.1');

const clientConfigGenerator = new UnifiedClientConfigGenerator(
outputRetrieval,
configContributors
);

await assert.rejects(
() => clientConfigGenerator.generateClientConfig(),
(error: AmplifyUserError) => {
assert.strictEqual(
error.message,
'Stack was not created with Amplify.'
);
assert.ok(error.resolution);
return true;
}
);
});

void it('throws user error if credentials are expired when getting backend outputs', async () => {
const outputRetrieval = mock.fn(() => {
throw new BackendOutputClientError(
Expand Down
14 changes: 14 additions & 0 deletions packages/client-config/src/unified_client_config_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ export class UnifiedClientConfigGenerator implements ClientConfigGenerator {
error
);
}
if (
error instanceof BackendOutputClientError &&
error.code === BackendOutputClientErrorType.METADATA_RETRIEVAL_ERROR
) {
throw new AmplifyUserError(
'NonAmplifyStackError',
{
message: 'Stack was not created with Amplify.',
resolution:
'Ensure the CloudFormation stack ID references a main stack created with Amplify, then re-run this command.',
},
error
);
}
if (
error instanceof BackendOutputClientError &&
error.code === BackendOutputClientErrorType.CREDENTIALS_ERROR
Expand Down

0 comments on commit 603b75d

Please sign in to comment.