Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classify pointing client config generator at metadata-less stack as u… #2024

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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