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

Conversation

@juliangruber
Copy link
Member

Previously we weren't successfully filtering out errors like ones with .code = 'ECONNRESET', because the String(err) only includes the message, no other properties:

> const err = new Error('message')
> err.code = 'ECONNRESET'
> String(err)
> // => Error: message

util.inspect() fixes this:

> util.inspect(err)
'Error: message\n' +
  '    at REPL22:1:11\n' +
  '    at Script.runInThisContext (node:vm:122:12)\n' +
  '    at REPLServer.defaultEval (node:repl:567:29)\n' +
  '    at bound (node:domain:433:15)\n' +
  '    at REPLServer.runBound [as eval] (node:domain:444:12)\n' +
  '    at REPLServer.onLine (node:repl:897:10)\n' +
  '    at REPLServer.emit (node:events:523:35)\n' +
  '    at REPLServer.emit (node:domain:489:12)\n' +
  '    at [_onLine] [as _onLine] (node:internal/readline/interface:415:12)\n' +
  '    at [_line] [as _line] (node:internal/readline/interface:886:18) {\n' +
  "  code: 'ECONNRESET'\n" +
  '}'

A potential downside is that it includes the stack, which could lead to false positives. If we only want to add the .code property, this would work as an alternative. @bajtos which do you think is better?

> String(err + err?.code)
'Error: messageECONNRESET

@juliangruber juliangruber requested a review from bajtos June 26, 2023 09:31
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

I guess inspect is good enough. We can replace it when it becomes a problem.

But I do have a suggestion to consider 👇🏻

lib/telemetry.js Outdated
setInterval(() => {
writeClient.flush().catch(err => {
if (!unactionableErrors.test(String(err))) {
if (!unactionableErrors.test(inspect(err))) {
Copy link
Member

Choose a reason for hiding this comment

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

How about applying the check on the error code string directly?

if (unactionableErrors.test(String(err))) return;
if (err?.code && unactionableErrors.test(String(err.code))) return;
Sentry.captureException(err)

Copy link
Member Author

Choose a reason for hiding this comment

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

I really like this, even simpler!

@juliangruber juliangruber merged commit 59f80dc into main Jun 27, 2023
@juliangruber juliangruber deleted the fix/telemetry-error-code branch June 27, 2023 08:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants