Skip to content

Commit

Permalink
fix: remove error incorrectly swallowed (fixes #13030)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhockett committed Aug 1, 2023
1 parent 4558111 commit 3229dd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
21 changes: 7 additions & 14 deletions packages/amplify-category-auth/src/commands/auth/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ export const run = async (context: $TSContext): Promise<void> => {
(resourceKey) => meta.auth[resourceKey].service === AmplifySupportedService.COGNITO,
);

try {
const resource = await amplify.removeResource(context, category, resourceName);
if (resource?.service === AmplifySupportedService.COGNITOUSERPOOLGROUPS) {
// update cli input here
const cliState = new AuthInputState(context, authResourceName[0]);
const cliInputPayload = cliState.getCLIInputPayload();
cliInputPayload.cognitoConfig.userPoolGroupList = [];
await cliState.saveCLIInputPayload(cliInputPayload);
}
} catch (err) {
printer.info(err.stack);
printer.error('There was an error removing the auth resource');
void context.usageData.emitError(err);
process.exitCode = 1;
const resource = await amplify.removeResource(context, category, resourceName);
if (resource?.service === AmplifySupportedService.COGNITOUSERPOOLGROUPS) {
// update cli input here
const cliState = new AuthInputState(context, authResourceName[0]);
const cliInputPayload = cliState.getCLIInputPayload();
cliInputPayload.cognitoConfig.userPoolGroupList = [];
await cliState.saveCLIInputPayload(cliInputPayload);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('remove-resource', () => {
},
serviceSuffix: { Lambda: '(function)', LambdaLayer: '(layer)' },
}),
).rejects.toThrowError('An error occurred when removing the resources from the local directory');
).rejects.toThrowError('Resource cannot be removed because it has a dependency on another resource');

expect(prompterMock.pick).toBeCalledWith('Choose the resource you would want to remove', [
{
Expand Down Expand Up @@ -211,7 +211,7 @@ describe('remove-resource', () => {

it('throw an error when the dependent resources has a specified resource', async () => {
await expect(removeResource(context as any, 'function', 'lambdaLayer1')).rejects.toThrowError(
'An error occurred when removing the resources from the local directory',
'Resource cannot be removed because it has a dependency on another resource',
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
$TSContext,
AmplifyError,
AmplifyException,
AmplifyFault,
exitOnNextTick,
pathManager,
Expand Down Expand Up @@ -97,8 +98,11 @@ export async function removeResource(
}

try {
return await deleteResourceFiles(context, category, resourceName, resourceDir);
return deleteResourceFiles(context, category, resourceName, resourceDir);
} catch (err) {
if (err instanceof AmplifyException) {
throw err;
}
throw new AmplifyFault(
'ResourceRemoveFault',
{ message: 'An error occurred when removing the resources from the local directory' },
Expand Down

0 comments on commit 3229dd5

Please sign in to comment.