Skip to content

Commit 6dfa4c3

Browse files
authored
Schemas: fix code generation on download failure (#1484)
When downloading code bindings for custom schemas (all schemas other than aws.schemas registry) fails with an error, the code generation logic tries to download code bindings (this automatically works for aws.schemas as they are pre-generated), if it fails with NotFound exception then we generate the code bindings. Problem: We used stack parameter from the Error interface to determine the error type, which seems to be not returned anymore. Solution: Use new parameter `name` which contains the error type.
1 parent 3953785 commit 6dfa4c3

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Schemas: download failure would not trigger code generation under certain conditions"
4+
}

src/eventSchemas/commands/downloadSchemaItemCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class SchemaCodeDownloader {
136136
zipContents = await this.downloader.download(request)
137137
} catch (err) {
138138
const error = err as Error
139-
if (error.stack && error.stack.includes('NotFoundException')) {
139+
if (error.name == 'ResourceNotFound') {
140140
//If the code generation wasn't previously kicked off, do so
141141
vscode.window.showInformationMessage(
142142
localize(

src/test/eventSchemas/commands/downloadSchemaItemCode.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ describe('SchemaCodeDownload', () => {
387387
assert.strictEqual(response, fileContent, `${expectedFilePath} :file content do not match`)
388388
})
389389

390-
it('should return error if downloading code fails with anything other than NotFoundException', async () => {
390+
it('should return error if downloading code fails with anything other than ResourceNotFound', async () => {
391391
const customError = new Error('Custom error')
392392
const codeDownloaderStub = sandbox.stub(downloader, 'download').returns(Promise.reject(customError))
393393

@@ -399,7 +399,7 @@ describe('SchemaCodeDownload', () => {
399399
assert.strictEqual(customError, error, 'Should throw Custom error')
400400
})
401401

402-
it('should generate code if download fails with NotFoundException and place it into requested directory', async () => {
402+
it('should generate code if download fails with ResourceNotFound and place it into requested directory', async () => {
403403
sandbox.stub(poller, 'pollForCompletion').returns(Promise.resolve('CREATE_COMPLETE'))
404404
const codeDownloaderStub = sandbox.stub(downloader, 'download')
405405
const codeGeneratorResponse: Schemas.PutCodeBindingResponse = {
@@ -408,7 +408,7 @@ describe('SchemaCodeDownload', () => {
408408
sandbox.stub(generator, 'generate').returns(Promise.resolve(codeGeneratorResponse))
409409

410410
const customError = new Error('Resource Not Found Exception')
411-
customError.stack = 'This should trigger the code in catch block - NotFoundException'
411+
customError.name = 'ResourceNotFound'
412412

413413
codeDownloaderStub.onCall(0).returns(Promise.reject(customError)) // should fail on first call
414414
codeDownloaderStub.onCall(1).returns(Promise.resolve(arrayBuffer)) // should succeed on second

0 commit comments

Comments
 (0)