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

NeonDbError does not preserve a stack trace when it is thrown #82

Closed
brettimus opened this issue May 23, 2024 · 1 comment · Fixed by #83
Closed

NeonDbError does not preserve a stack trace when it is thrown #82

brettimus opened this issue May 23, 2024 · 1 comment · Fixed by #83

Comments

@brettimus
Copy link
Contributor

brettimus commented May 23, 2024

Steps to reproduce

  • Execute a query with neon that will return a NeonDbError
  • Catch the error into a variable called error
  • Inspect error.stack (and error.sourceError.stack if you're so inclined)

Expected result

The NeonDbError should include a stack trace whenever possible

Actual result

Instances of NeonDbError do not include a stack trace

Environment

Cloudflare workers (but also everywhere)

Logs, links

The stack trace of an error is helpful for error monitoring tools, to be able to link back to the line of code that triggered the error.

As of writing, NeonDbError does indeed inherit from Error, but it does not include a stack trace, as Error usually does.

This would be possible to implement with a quick code change, adding a constructor to the custom NeonDbError class:

  constructor(message: string) {
    super(message);
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, BugError);
    }
  }

I'm not sure of serverless environment support for Error.captureStackTrace, since this is not a web standard, per se. However, it does exist for Cloudflare Workers. That's why there's a conditional check for Error.captureStackTrace.

I'm willing to pick this up in a PR if you all are open to it!! Would be more than happy to contribute.

@brettimus
Copy link
Contributor Author

I put up a PR in case this is something you all would like to move ahead with! #83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant