-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-4848): Add runtime error handling to logging #3971
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
Conversation
src/mongo_logger.ts
Outdated
? value.name | ||
: 'anonymous function'; | ||
} catch (e) { | ||
strToTruncate = `... ESJON failed : Error ${e.message}`; |
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.
There's a typo here (EJSON
) but it might be worth wording this a bit more explicitly anyway:
strToTruncate = `... ESJON failed : Error ${e.message}`; | |
strToTruncate = `Extended JSON serialization failed with: ${e.message}`; |
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.
Sounds good to me!
src/utils.ts
Outdated
@@ -171,8 +171,13 @@ export function applyRetryableWrites<T extends HasRetryableWrites>(target: T, db | |||
* @param value - An object that could be a promise | |||
* @returns true if the provided value is a Promise | |||
*/ | |||
export function isPromiseLike<T = any>(value?: PromiseLike<T> | void): value is Promise<T> { | |||
return !!value && typeof value.then === 'function'; | |||
export function isPromiseLike<T = any>(value?: unknown): value is PromiseLike<T> { |
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.
It's a obviously a tradeoff, but I'd consider doing
export function isPromiseLike<T = any>(value?: unknown): value is PromiseLike<T> { | |
export function isPromiseLike<T = unknown>(value?: unknown): value is PromiseLike<T> { |
instead so one doesn't potentially introduce a hidden any
by default each time they're using this function
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.
Sounds good, changed it :)
d9eb4e8
Note for Reviewers
Look at changes commit by commit to easily separate async and sync changes
Description
This ticket is a subtask of NODE-4816 (Add Error Handling to the Logger).
Essentially, these changes ensure that the logger does not crash the user's application at runtime, at any point after options are parsed.
What is changing?
Add support for runtime error handling (ensure no constructors for loggers throw unless given type errors, log.write, stringifyWithMaxLen, defaultLogTransform).
Add async support for log.write function
See all unit tests defined under runtime error handling in Kickoff Document, and under mongodbLogPath stream handling (since some of this must be done at runtime).
Note: There are no changes to any of the constructors of
LoggableEvent
classes or calls to emitAndLog / variants because noLoggableEvent
constructors have any explicit errors thrown. In addition, no arguments toLoggableEvent
constructors are ever invalid at the time of construction.Is there new documentation needed for these changes?
After NODE-5672 (Release Logger)
What is the motivation for this change?
To ensure we don't crash the user's application through the logger.
Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript