Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(amplify-nodejs-function-runtime-provider): fix lambda error format (
#6350) return proper error message and stack if a string error is provided return string error as is fix #5553
- Loading branch information
Showing
7 changed files
with
71 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/amplify-nodejs-function-runtime-provider/src/__tests__/utils/invokeExecute.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as execa from 'execa'; | ||
import path from 'path'; | ||
import { invoke } from '../../utils/invoke'; | ||
|
||
jest.setTimeout(60000); | ||
jest.mock('../../utils/invokeUtils', () => ({ | ||
...(jest.requireActual('../../utils/invokeUtils') as any), | ||
getLambdaChildProcess: jest.fn().mockImplementation((environment: any, functionName: string = 'execute.js') => { | ||
return execa.node(path.join(__dirname, '..', '..', '..', 'lib', 'utils', functionName), [], { | ||
env: environment || {}, | ||
}); | ||
}) | ||
})); | ||
|
||
describe('test invoke with execute', () => { | ||
it('should fail with proper error', async () => { | ||
await expect(invoke({ | ||
packageFolder: __dirname, | ||
handler: 'handlers.undefinedVariableHandler', | ||
event: '{}', | ||
environment: {} | ||
})).rejects.toMatchObject({ | ||
message: 'undedvar is not defined', | ||
stack: expect.stringContaining('ReferenceError: undedvar is not defined'), | ||
type: 'Lambda:Unhandled' | ||
}) | ||
}); | ||
|
||
it('should fail with string error', async () => { | ||
await expect(invoke({ | ||
packageFolder: __dirname, | ||
handler: 'handlers.stringErrorHandler', | ||
event: '{}', | ||
environment: {} | ||
})).rejects.toMatchObject({ | ||
type: 'Lambda:Unhandled', | ||
message: 'Unknown Error' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 2 additions & 6 deletions
8
packages/amplify-nodejs-function-runtime-provider/src/utils/invoke.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
packages/amplify-nodejs-function-runtime-provider/src/utils/invokeOptions.ts
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
packages/amplify-nodejs-function-runtime-provider/src/utils/invokeUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import path from 'path'; | ||
import * as execa from 'execa'; | ||
|
||
export type InvokeOptions = { | ||
packageFolder: string; | ||
handler: string; | ||
event: string; | ||
context?: object; | ||
environment?: { [key: string]: string }; | ||
}; | ||
|
||
export const getLambdaChildProcess = (environment: any, functionName: string = 'execute.js'): execa.ExecaChildProcess => { | ||
return execa.node(path.join(__dirname, functionName), [], { | ||
env: environment || {}, | ||
}); | ||
} |