Skip to content

Commit 1e5edd9

Browse files
committed
Prevent circular resolution issues.
1 parent 2e30ccd commit 1e5edd9

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19+
const stringify = require('json-stringify-safe');
20+
1921
let originalError = Error;
2022
class ApplicationErrorExtension extends Error {
2123
constructor(message, rawCode, ...args) {
2224
const code = rawCode || typeof message === 'string' && message || typeof message === 'object' && message.code || null;
2325

2426
const codeString = `(${code || 'UnspecifiedApplicationErrorCode'})`;
25-
const stringErrorMessage = `${codeString}: ${JSON.stringify(message || '')}`;
27+
const stringErrorMessage = `${codeString}: ${stringify(message || '')}`;
2628
super(stringErrorMessage, ...args);
2729

2830
if (typeof originalError.captureStackTrace !== 'undefined') {
@@ -39,7 +41,7 @@ class ApplicationErrorExtension extends Error {
3941

4042
toString() {
4143
const codeString = `(${this.code || 'UnspecifiedApplicationErrorCode'})`;
42-
return `${codeString}: ${JSON.stringify(this.message || '')}`;
44+
return `${codeString}: ${stringify(this.message || '')}`;
4345
}
4446

4547
toJSON() {
@@ -75,7 +77,7 @@ Error.create = function(errorObject, code) {
7577
Error.prototype.create = Error.create;
7678
Error.prototype.toString = function() {
7779
const codeString = this.code ? ` (${this.code})` : '';
78-
return this.message ? `ErrorObjectPolyFill${codeString}: ${JSON.stringify(this.message)}` : 'ErrorObjectPolyFill';
80+
return this.message ? `ErrorObjectPolyFill${codeString}: ${stringify(this.message)}` : 'ErrorObjectPolyFill';
7981
};
8082
Error.prototype.inspect = Error.prototype.toString;
8183
Error.prototype.toJSON = function() {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"lint": "eslint --ext .js tests index.js",
1313
"test": "mocha tests/**/*.js -R spec"
1414
},
15-
"dependencies": {},
15+
"dependencies": {
16+
"json-stringify-safe": "^5.0.1"
17+
},
1618
"devDependencies": {
1719
"@typescript-eslint/eslint-plugin": "^3.1.0",
1820
"@typescript-eslint/parser": "^3.1.0",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,11 @@ json-stable-stringify-without-jsonify@^1.0.1:
13721372
resolved "https://registry.yarnpkg.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz#9db7b59496ad3f3cfef30a75142d2d930ad72651"
13731373
integrity sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==
13741374

1375+
json-stringify-safe@^5.0.1:
1376+
version "5.0.1"
1377+
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
1378+
integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==
1379+
13751380
json5@^1.0.1:
13761381
version "1.0.2"
13771382
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593"

0 commit comments

Comments
 (0)