Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Conversation

@plibither8
Copy link
Contributor

@plibither8 plibither8 commented Jul 8, 2022

This PR is completes https://github.com/sourcegraph/sourcegraph/issues/26582 and builds upon this PR in the codemod repo.


This PR:

  1. Enables warning for the no-unexplained-console-error eslint rule created here
  2. Logs to console the exceptions that were passed to Sentry through Sentry.captureException in development mode.

Test plan

Manually checked for warnings created by eslint VS Code extension when console.error calls are uncommented.

App preview:

Check out the client app preview documentation to learn more.

@plibither8
Copy link
Contributor Author

The eslint step in the buildkite check is expectedly failing, since it is dependent on this PR to be merged first and uploaded to npm.

Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Awesome! Left a couple of questions and curious to hear what you think of them.

// errors to console, and don't send any events forward
if (process.env.NODE_ENV === 'development') {
Sentry.onLoad(() => {
Sentry.init({
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about reusing the SDK configuration between these two calls if we need both of them?

For now, they are lightweight, but we might use more configuration fields (e.g., integrations) that can affect beforeSend behavior. Having inconsistent Sentry logic depending on flags might be confusing.

// If in development mode, initialize sentry only to log
// errors to console, and don't send any events forward
if (process.env.NODE_ENV === 'development') {
Sentry.onLoad(() => {
Copy link
Member

Choose a reason for hiding this comment

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

To ease the debugging of errors logged via Sentry.captureException in the development environment, we may want to introduce a utility that encapsulates internal implementation details (e.g., what service do we use for error tracking, when is it available, when to output to the console). Then consumers would be able to use it without extra safety checks like in the ErrorBoundary component.

UPD: thinking a bit more about this it's a good case for introducing a generalized logger service that could encapsulate error tracking, debug logs, telemetry service, etc. We can discuss this idea and consider introducing it in one of the follow-up PRs.

const logger = useLogger()

logger.error(error, { additionalDetails: true })
logger.debug('Something awesome happened!', { additionalDetails: true })


// If in development mode, initialize sentry only to log
// errors to console, and don't send any events forward
if (process.env.NODE_ENV === 'development') {
Copy link
Member

Choose a reason for hiding this comment

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

We might not have the Sentry global variable in the development environment, and I see that it's not clear from the type defined above. We can change it to:

declare global {
    const Sentry: SentrySDK | undefined
}

Currently it's loaded only when SOURCEGRAPHDOTCOM_MODE === true.

Comment on lines 19 to 20
// eslint-disable-next-line @sourcegraph/sourcegraph/no-unexplained-console-error
console.error(error)
Copy link
Member

Choose a reason for hiding this comment

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

Could we leave a comment explaining why we need to log errors here to the console, as the new ESLint rule suggests?

@plibither8 plibither8 force-pushed the mihir/26582-enable-console.error-rule branch from 986473e to db37d64 Compare July 18, 2022 11:47
@eseliger
Copy link
Member

As part of #wg-delete-week I am going to close this PR. If it’s still needed, feel free to reopen and restore the branch.

@eseliger eseliger closed this Jan 10, 2024
@eseliger eseliger deleted the mihir/26582-enable-console.error-rule branch January 10, 2024 20:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants