Skip to content

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

Merged
merged 9 commits into from
Jan 24, 2024

Conversation

aditi-khare-mongoDB
Copy link
Contributor

@aditi-khare-mongoDB aditi-khare-mongoDB commented Jan 19, 2024

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 no LoggableEvent constructors have any explicit errors thrown. In addition, no arguments to LoggableEvent 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

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@aditi-khare-mongoDB aditi-khare-mongoDB changed the title feat(NODE-4848): Runtime Error Handling for Logging feat(NODE-4848): Add runtime error handling to Logging Jan 19, 2024
@aditi-khare-mongoDB aditi-khare-mongoDB changed the title feat(NODE-4848): Add runtime error handling to Logging feat(NODE-4848): Add runtime error handling to logging Jan 19, 2024
@aditi-khare-mongoDB aditi-khare-mongoDB marked this pull request as ready for review January 19, 2024 19:45
@nbbeeken nbbeeken self-assigned this Jan 19, 2024
@nbbeeken nbbeeken added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jan 19, 2024
@nbbeeken nbbeeken self-requested a review January 19, 2024 19:58
? value.name
: 'anonymous function';
} catch (e) {
strToTruncate = `... ESJON failed : Error ${e.message}`;
Copy link
Contributor

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:

Suggested change
strToTruncate = `... ESJON failed : Error ${e.message}`;
strToTruncate = `Extended JSON serialization failed with: ${e.message}`;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me!

nbbeeken
nbbeeken previously approved these changes Jan 23, 2024
@nbbeeken nbbeeken added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jan 23, 2024
addaleax
addaleax previously approved these changes Jan 24, 2024
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> {
Copy link
Contributor

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

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, changed it :)

@aditi-khare-mongoDB aditi-khare-mongoDB dismissed stale reviews from addaleax and nbbeeken via d9eb4e8 January 24, 2024 16:27
@nbbeeken nbbeeken merged commit 38fb2e4 into main Jan 24, 2024
@nbbeeken nbbeeken deleted the NODE-4848/runtime-error-handling-logging branch January 24, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants