Skip to content
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

Add first use case - error handler code #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions use-cases/error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Use Case - Error Handlng Code

Grace is writng a Node.js server application using plenty of userland npm modules. She uses a third party service for logging server Errors to handle them before closing the server.

For example:
```
lib.get('/', async (request, reply) => {
const data = await getReplyFromDatabaseUsingModules(request);
return { data }
});
```

## User Expectation

a thrown error from `getReplyFromDatabaseUsingModules` should get observed at the process uncaught error handler to be logged even if the library error handler does not catch the error.
Copy link
Member

Choose a reason for hiding this comment

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

i'm confused; if lib.get does handle the error, then it must not be observed on the uncaught exception handler. perhaps:

Suggested change
a thrown error from `getReplyFromDatabaseUsingModules` should get observed at the process uncaught error handler to be logged even if the library error handler does not catch the error.
a thrown error from `getReplyFromDatabaseUsingModules` must be observed with the process uncaught error handler to be logged if (and only if) the library error handler does not catch the error.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a user expectation I don't suspect they use the RFC "MUST" in how they would describe it 😅

Copy link
Member

Choose a reason for hiding this comment

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

I mean im sure they don’t use the terms, but I’m also sure the meaning is what they intend.

Grace should be able to debug her server using the thrown error.

## What to Test

We may want to test the code paths of the `uncaughtException` and `unhandledRejection` handlers for user-land tampering.

## What Not to Test

We should probably not test any code the error-logging library uses as it is a reasonable expectation for error handling related libraries to be robust on their own.

## Out of Scope

We may want to consider that not adding a listener to those events and to instead log these errors by listening to stderr/stdout is a more robust practice that is more resiliant and would work in cases such as the user calling `process.exit` directly. It may be worth it to add a recommenation so users do that however we should consider error handling code being resiliant as a user expectation.
Copy link

Choose a reason for hiding this comment

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

I think the stderr/stdout could be on scope, because if node core is not reliable, the error logged on stderr might be not as useful as it could be – e.g. a TypeError: undefined is not a function when the error thrown by getReplyFromDatabaseUsingModules has nothing to do with it


We cannot reasonably make a stronger guarantee such that any error handling code even in userland should be robust to tampering with built ins. For example if the user alters `lib.get` to throw or `EventTarget.on` to throw we cannot guard against that reasonably but ideally the error created would still reach the global Node.js process error handler.
Copy link
Member Author

Choose a reason for hiding this comment

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

EventTarget -> EventEmitter