Skip to content

Commit acc8cb1

Browse files
fix(pouchdb-errors): guard Error.stack access when stack is inaccessible
1 parent f6d6735 commit acc8cb1

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

  • packages/node_modules/pouchdb-errors/src

packages/node_modules/pouchdb-errors/src/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ function createError(error, reason) {
6060
pouchError[name] = error[name];
6161
}
6262

63+
try {
64+
if (pouchError.stack === undefined) {
65+
pouchError.stack = (new Error()).stack;
66+
}
67+
} catch (e) {
68+
pouchError.stack = 'No stack trace available';
69+
}
70+
6371
if (reason !== undefined) {
6472
pouchError.reason = reason;
6573
}
@@ -92,10 +100,6 @@ function generateErrorFromResponse(err) {
92100
err.message = err.message || err.reason;
93101
}
94102

95-
if (!('stack' in err)) {
96-
err.stack = (new Error()).stack;
97-
}
98-
99103
return err;
100104
}
101105

0 commit comments

Comments
 (0)