-
Notifications
You must be signed in to change notification settings - Fork 4
node uncaught error handler #42
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a9ef47
Node unhandled exceptions/rejections
konraddysput c13a90a
Correct submission URL
konraddysput 95b6893
Unhandled exception handler
konraddysput 32b0289
Do not exted launch settings
konraddysput f2ea04e
Respect unhandled rejection mode in app
konraddysput 99ef752
Improve warning messages generated on unhandled promise rejection. Ad…
konraddysput 6c3811d
Fixed typo in node_env
konraddysput b58e921
Move functions to consts
konraddysput File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,55 @@ | ||
| export class NodeOptionReader { | ||
| /** | ||
| * Read option based on the option name. If the option doesn't start with `--` | ||
| * additional prefix will be added. | ||
| * @param optionName option name | ||
| * @returns option value | ||
| */ | ||
| public static read( | ||
| optionName: string, | ||
| argv: string[] = process.execArgv, | ||
| nodeOptions: string | undefined = process.env['NODE_OPTIONS'], | ||
| ): string | boolean | undefined { | ||
| /** | ||
| * exec argv overrides NODE_OPTIONS. | ||
| * for example: | ||
| * yarn start = NODEW_ENV=production node --unhandled-rejections=none ./lib/index.js | ||
| * NODE_OPTIONS='--unhandled-rejections=throw' yarn start | ||
| * | ||
| * Even if NODE_OPTIONS have unhandled rejections set to throw, the value passed in argv | ||
| * will be used. | ||
| */ | ||
| if (!optionName.startsWith('--')) { | ||
| optionName = '--' + optionName; | ||
| } | ||
|
|
||
| const commandOption = argv.find((n) => n.startsWith(optionName)); | ||
|
|
||
| function readOptionValue(optionName: string, commandOption: string): string | boolean | undefined { | ||
| let result = commandOption.substring(optionName.length); | ||
| if (!result) { | ||
| return true; | ||
| } | ||
| if (result.startsWith('=')) { | ||
| result = result.substring(1); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| if (commandOption) { | ||
| return readOptionValue(optionName, commandOption); | ||
| } | ||
|
|
||
| if (!nodeOptions) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const nodeOption = nodeOptions.split(' ').find((n) => n.startsWith(optionName)); | ||
|
|
||
| if (!nodeOption) { | ||
| return undefined; | ||
| } | ||
| return readOptionValue(optionName, nodeOption); | ||
| } | ||
| } |
This file contains hidden or 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,92 @@ | ||
| import { NodeOptionReader } from '../../src/common/NodeOptionReader'; | ||
| describe('Node options reader', () => { | ||
| describe('argv', () => { | ||
| it('should read --unhandled-rejections option', () => { | ||
| const option = 'unhandled-rejections'; | ||
| const expectedValue = 'none'; | ||
| const optionWithValue = `--${option}=${expectedValue}`; | ||
|
|
||
| const value = NodeOptionReader.read(option, [optionWithValue]); | ||
|
|
||
| expect(value).toEqual(expectedValue); | ||
| }); | ||
|
|
||
| it('should read boolean value option if the option is defined', () => { | ||
| const option = 'trace-warnings'; | ||
| const optionWithValue = `--${option}`; | ||
|
|
||
| const value = NodeOptionReader.read(option, [optionWithValue]); | ||
|
|
||
| expect(value).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should read undefined if the option is not available', () => { | ||
| const value = NodeOptionReader.read('', ['']); | ||
|
|
||
| expect(value).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should read --unhandled-rejections option with option passed with --', () => { | ||
| const option = '--unhandled-rejections'; | ||
| const expectedValue = 'warn'; | ||
| const optionWithValue = `${option}=${expectedValue}`; | ||
|
|
||
| const value = NodeOptionReader.read(option, [optionWithValue]); | ||
|
|
||
| expect(value).toEqual(expectedValue); | ||
| }); | ||
|
|
||
| it('should not read --unhandled-rejections if its not available', () => { | ||
| const value = NodeOptionReader.read('unhandled-rejections'); | ||
|
|
||
| expect(value).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should prefer --unhandled-rejections available in argv and ignore NODE_OPTIONS', () => { | ||
| const option = '--unhandled-rejections'; | ||
| const expectedValue = 'warn'; | ||
| const expectedOptionWithValue = `${option}=${expectedValue}`; | ||
| const invalidOptionWithValue = `${option}=none`; | ||
|
|
||
| const value = NodeOptionReader.read( | ||
| 'unhandled-rejections', | ||
| [expectedOptionWithValue], | ||
| invalidOptionWithValue, | ||
| ); | ||
|
|
||
| expect(value).toEqual(expectedValue); | ||
| }); | ||
| }); | ||
|
|
||
| describe('NODE_OPTIONS', () => { | ||
| it('should read --unhandled-rejections option from NODE_OPTIONS', () => { | ||
| const option = 'unhandled-rejections'; | ||
| const expectedValue = 'throw'; | ||
| const optionWithValue = `--${option}=${expectedValue}`; | ||
|
|
||
| const value = NodeOptionReader.read(option, [], optionWithValue); | ||
|
|
||
| expect(value).toEqual(expectedValue); | ||
| }); | ||
|
|
||
| it('should read --unhandled-rejections option if multiple NODE_OPTIONS are available', () => { | ||
| const option = 'unhandled-rejections'; | ||
| const expectedValue = 'throw'; | ||
| const optionWithValue = `--${option}=${expectedValue}`; | ||
|
|
||
| const value = NodeOptionReader.read( | ||
| option, | ||
| [], | ||
| `--max-old-space-size=8192 ${optionWithValue} --track-heap-objects`, | ||
| ); | ||
|
|
||
| expect(value).toEqual(expectedValue); | ||
| }); | ||
|
|
||
| it('should not read --unhandled-rejections if its not available', () => { | ||
| const value = NodeOptionReader.read('unhandled-rejections'); | ||
|
|
||
| expect(value).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.