-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add error mapping for Amplify app not found in specified region #2313
base: main
Are you sure you want to change the base?
Changes from 13 commits
16e96d7
f0e0bbe
645e1e0
28a37d6
afb801e
a2c4031
a5692a0
6e73f46
33b2ccd
536dad0
eab450f
b400709
37b62bb
3236c1e
31b406a
357babb
5c9b41f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/backend-cli': patch | ||
--- | ||
|
||
Added error mapping for app name not available in the region |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,11 @@ import { SandboxBackendIdResolver } from '../../sandbox/sandbox_id_resolver.js'; | |
import { S3Client } from '@aws-sdk/client-s3'; | ||
import { AmplifyClient } from '@aws-sdk/client-amplify'; | ||
import { CloudFormationClient } from '@aws-sdk/client-cloudformation'; | ||
import { | ||
BackendOutputClientError, | ||
BackendOutputClientErrorType, | ||
} from '@aws-amplify/deployed-backend-client'; | ||
import { AmplifyUserError } from '@aws-amplify/platform-core'; | ||
|
||
void describe('generate outputs command', () => { | ||
const clientConfigGeneratorAdapter = new ClientConfigGeneratorAdapter({ | ||
|
@@ -249,3 +254,101 @@ void describe('generate outputs command', () => { | |
assert.match(output, /Arguments .* mutually exclusive/); | ||
}); | ||
}); | ||
|
||
void describe('GenerateOutputsCommand error handling', () => { | ||
let clientConfigGenerator: ClientConfigGeneratorAdapter; | ||
let backendIdentifierResolver: AppBackendIdentifierResolver; | ||
let generateOutputsCommand: GenerateOutputsCommand; | ||
|
||
beforeEach(() => { | ||
// Mock the dependencies | ||
clientConfigGenerator = { | ||
generateClientConfigToFile: mock.fn(), | ||
} as unknown as ClientConfigGeneratorAdapter; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use the existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated it, keeping it consistent |
||
backendIdentifierResolver = { | ||
resolveDeployedBackendIdentifier: mock.fn(), | ||
} as unknown as AppBackendIdentifierResolver; | ||
|
||
generateOutputsCommand = new GenerateOutputsCommand( | ||
clientConfigGenerator, | ||
backendIdentifierResolver | ||
); | ||
}); | ||
|
||
void it('should throw AmplifyUserError when NO_APP_FOUND_ERROR occurs', async () => { | ||
// Mock the resolver to simulate successful resolution | ||
mock.method( | ||
backendIdentifierResolver, | ||
'resolveDeployedBackendIdentifier', | ||
() => Promise.resolve({ appId: 'test-app', branchName: 'main' }) | ||
); | ||
|
||
// Mock the generator to throw NO_APP_FOUND_ERROR | ||
mock.method(clientConfigGenerator, 'generateClientConfigToFile', () => { | ||
throw new BackendOutputClientError( | ||
BackendOutputClientErrorType.NO_APP_FOUND_ERROR, | ||
'No Amplify app found in the specified region' | ||
); | ||
}); | ||
try { | ||
await generateOutputsCommand.handler({ | ||
stack: undefined, | ||
appId: 'test-app', | ||
'app-id': 'test-app', | ||
branch: 'main', | ||
format: undefined, | ||
outDir: undefined, | ||
'out-dir': undefined, | ||
outputsVersion: '1.3', | ||
'outputs-version': '1.3', | ||
_: [], | ||
$0: 'command-name', | ||
}); | ||
assert.fail('Expected error was not thrown'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated it |
||
} catch (error) { | ||
if (error instanceof AmplifyUserError) { | ||
assert.equal(error.name, 'AmplifyAppNotFoundError'); | ||
assert.equal( | ||
error.message, | ||
'No Amplify app found in the specified region' | ||
); | ||
} | ||
} | ||
}); | ||
|
||
void it('should re-throw other types of errors', async () => { | ||
// Mock the resolver to simulate successful resolution | ||
mock.method( | ||
backendIdentifierResolver, | ||
'resolveDeployedBackendIdentifier', | ||
() => Promise.resolve({ appId: 'test-app', branchName: 'main' }) | ||
); | ||
|
||
// Mock the generator to throw a different type of error | ||
const originalError = new Error('Some other error'); | ||
mock.method(clientConfigGenerator, 'generateClientConfigToFile', () => { | ||
throw originalError; | ||
}); | ||
|
||
try { | ||
await generateOutputsCommand.handler({ | ||
stack: undefined, | ||
appId: 'test-app', | ||
'app-id': 'test-app', | ||
branch: 'main', | ||
format: undefined, | ||
outDir: undefined, | ||
'out-dir': undefined, | ||
outputsVersion: '1.3', | ||
'outputs-version': '1.3', | ||
_: [], | ||
$0: 'command-name', | ||
}); | ||
assert.fail('Expected error was not thrown'); | ||
} catch (error) { | ||
assert.equal(error, originalError); | ||
assert(!(error instanceof AmplifyUserError)); | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the lint, don't use instanceof as it might not work if there are multiple versions of DeployedBackendClient package in the node_modules.