diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f17033a..e8ddb5557 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ This driver uses semantic versioning: - A change in the major version (e.g. 1.Y.Z -> 2.0.0) indicates _breaking_ changes that require changes in your code to upgrade. +## [Unreleased] + +### Fixed + +- Stack traces are now improved for most errors when using `precaptureStackTraces` + + Previously this option would only affect network errors, making it far less + useful than intended. Now parsing errors, `ArangoError` instances and HTTP + errors also receive improved error stack traces when this option is enabled. + ## [7.3.0] - 2021-03-08 ### Changed diff --git a/src/connection.ts b/src/connection.ts index 7cfb02a05..1937d98b3 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -894,6 +894,9 @@ export class Connection { parsedBody = res.body.toString("utf-8"); } e.response = res; + if (task.stack) { + e.stack += task.stack; + } reject(e); return; } @@ -905,10 +908,18 @@ export class Connection { } if (isArangoErrorResponse(parsedBody)) { res.body = parsedBody; - reject(new ArangoError(res)); + const err = new ArangoError(res); + if (task.stack) { + err.stack += task.stack; + } + reject(err); } else if (res.statusCode && res.statusCode >= 400) { res.body = parsedBody; - reject(new HttpError(res)); + const err = new HttpError(res); + if (task.stack) { + err.stack += task.stack; + } + reject(err); } else { if (!expectBinary) res.body = parsedBody; resolve(transform ? transform(res) : (res as any)); diff --git a/src/test/_config.ts b/src/test/_config.ts index a89f060ea..e766e784b 100644 --- a/src/test/_config.ts +++ b/src/test/_config.ts @@ -4,19 +4,18 @@ const ARANGO_URL = process.env.TEST_ARANGODB_URL || "http://localhost:8529"; const ARANGO_VERSION = Number( process.env.ARANGO_VERSION || process.env.ARANGOJS_DEVEL_VERSION || 39999 ); -const ARANGO_LOAD_BALANCING_STRATEGY = process.env.TEST_ARANGO_LOAD_BALANCING_STRATEGY as LoadBalancingStrategy | undefined; +const ARANGO_LOAD_BALANCING_STRATEGY = process.env + .TEST_ARANGO_LOAD_BALANCING_STRATEGY as LoadBalancingStrategy | undefined; -export const config: { - url: NonNullable; - arangoVersion: NonNullable; - loadBalancingStrategy?: Config["loadBalancingStrategy"]; -} = ARANGO_URL.includes(",") +export const config: Config = ARANGO_URL.includes(",") ? { url: ARANGO_URL.split(",").filter((s) => Boolean(s)), arangoVersion: ARANGO_VERSION, + precaptureStackTraces: true, loadBalancingStrategy: ARANGO_LOAD_BALANCING_STRATEGY || "ROUND_ROBIN", } : { url: ARANGO_URL, arangoVersion: ARANGO_VERSION, + precaptureStackTraces: true, };