From 6a9a2d2daf1c622c7c57c9e529665b8537e73377 Mon Sep 17 00:00:00 2001 From: Brett Beutell Date: Fri, 27 Sep 2024 18:12:07 +0200 Subject: [PATCH] Add stack traces to NeonDbError when captureStackTrace is available (#83) Fixes https://github.com/neondatabase/serverless/issues/82 --- CHANGELOG.md | 4 ++++ export/httpQuery.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f060f2..090c690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## UNRELEASED + +Capture stack traces in `NeonDbError`, if `Error.captureStackTrace` is available. + ## 0.9.3 (2024-05-09) Expose all error information fields on `NeonDbError` objects thrown when using the http fetch transport. diff --git a/export/httpQuery.ts b/export/httpQuery.ts index a7b56ee..0811c31 100644 --- a/export/httpQuery.ts +++ b/export/httpQuery.ts @@ -28,6 +28,14 @@ export class NeonDbError extends Error { routine: string | undefined; sourceError: Error | undefined; + + constructor(message: string) { + super(message); + + if ("captureStackTrace" in Error && typeof Error.captureStackTrace === "function") { + Error.captureStackTrace(this, NeonDbError); + } + } } interface ParameterizedQuery {