Skip to content

Commit

Permalink
Fix precaptureStackTraces
Browse files Browse the repository at this point in the history
Fixes #722.
  • Loading branch information
pluma committed Mar 9, 2021
1 parent 5696762 commit 4130b16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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));
Expand Down
11 changes: 5 additions & 6 deletions src/test/_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config["url"]>;
arangoVersion: NonNullable<Config["arangoVersion"]>;
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,
};

0 comments on commit 4130b16

Please sign in to comment.