facebook / facebook/docusaurus

Use reportError() API

Open
#6,747 0 comments 0 reactions 0 assignees View on GitHub
proposal
Dominant language
TypeScript
Stars
66.2k
Forks
10k
Avg merge
1d 3h
Merged PRs (30d)
52

Description

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#reporting-new-issues).

### Motivation

Using the new `reportError` api permits to trigger `window.onerror` and let users (or error reporting services) to plug their own error handling behavior

https://www.stefanjudis.com/blog/reporterror-a-method-to-report-to-global-event-handlers/

This is not 100% supported though

https://caniuse.com/?search=reportError

React recently merged a PR using this feature

https://github.com/facebook/react/pull/23207

```tsx
/* global reportError */
export const logRecoverableError =
typeof reportError === 'function'
? // In modern browsers, reportError will dispatch an error event,
// emulating an uncaught JavaScript error.
reportError
: (error: mixed) => {
// In older browsers and test environments, fallback to console.error.
// eslint-disable-next-line react-internal/no-production-logging, react-internal/warning-args
console.error(error);
};
```

We should probably do the same and use `reportError` for any recoverable error that we usually `console.error`.

There are many places where we deal with recoverable errors, particularly around localstorage usage.

We could eventually expose a core error reporting API that triggers lifecycle a new client module lifecycle event, this could allow users to build error reporting plugins like Sentry?

### Self-service

- [ ] I'd be willing to do some initial work on this proposal myself.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.