@tryghost/errors 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/errors.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const uuid = require('uuid');
2
2
  const merge = require('lodash/merge');
3
3
  const isString = require('lodash/isString');
4
- const cloneDeep = require('lodash/cloneDeep');
5
4
  const utils = require('./utils');
6
5
 
7
6
  class GhostError extends Error {
@@ -71,34 +70,6 @@ class GhostError extends Error {
71
70
  });
72
71
  }
73
72
  }
74
-
75
- prepareErrorForUser() {
76
- const error = cloneDeep(this);
77
-
78
- let stackbits = error.stack.split(/\n/);
79
-
80
- // We build this up backwards, so we always insert at position 1
81
-
82
- if (process.env.NODE_ENV === 'production') {
83
- stackbits.splice(1, stackbits.length - 1);
84
- } else {
85
- // Clearly mark the strack trace
86
- stackbits.splice(1, 0, `Stack Trace:`);
87
- }
88
-
89
- // Add in our custom cotext and help methods
90
-
91
- if (this.help) {
92
- stackbits.splice(1, 0, `${this.help}`);
93
- }
94
-
95
- if (this.context) {
96
- stackbits.splice(1, 0, `${this.context}`);
97
- }
98
-
99
- error.stack = stackbits.join('\n');
100
- return error;
101
- }
102
73
  }
103
74
 
104
75
  const ghostErrors = {
@@ -349,5 +320,6 @@ const ghostErrorsWithBase = Object.assign({}, ghostErrors, {GhostError});
349
320
  module.exports.utils = {
350
321
  serialize: utils.serialize.bind(ghostErrorsWithBase),
351
322
  deserialize: utils.deserialize.bind(ghostErrorsWithBase),
352
- isGhostError: utils.isGhostError.bind(ghostErrorsWithBase)
323
+ isGhostError: utils.isGhostError.bind(ghostErrorsWithBase),
324
+ prepareStackForUser: utils.prepareStackForUser
353
325
  };
package/lib/utils.js CHANGED
@@ -183,6 +183,36 @@ exports.deserialize = function deserialize(errorFormat) {
183
183
  return internalError;
184
184
  };
185
185
 
186
+ /**
187
+ * @description Replace the stack with a user-facing one
188
+ * @params {Error} err
189
+ */
190
+ exports.prepareStackForUser = function prepareStackForUser(error) {
191
+ let stackbits = error.stack.split(/\n/);
192
+
193
+ // We build this up backwards, so we always insert at position 1
194
+
195
+ if (process.env.NODE_ENV === 'production') {
196
+ stackbits.splice(1, stackbits.length - 1);
197
+ } else {
198
+ // Clearly mark the strack trace
199
+ stackbits.splice(1, 0, `Stack Trace:`);
200
+ }
201
+
202
+ // Add in our custom cotext and help methods
203
+
204
+ if (this.help) {
205
+ stackbits.splice(1, 0, `${this.help}`);
206
+ }
207
+
208
+ if (this.context) {
209
+ stackbits.splice(1, 0, `${this.context}`);
210
+ }
211
+
212
+ error.stack = stackbits.join('\n');
213
+ return error;
214
+ };
215
+
186
216
  /**
187
217
  * @description Check whether an error instance is a GhostError.
188
218
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/errors",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "repository": "https://github.com/TryGhost/Utils/tree/main/packages/errors",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
@@ -28,5 +28,5 @@
28
28
  "lodash": "^4.17.21",
29
29
  "uuid": "^8.3.2"
30
30
  },
31
- "gitHead": "deb1552864a7da3430e0f0854ff013b5d0aa4a0c"
31
+ "gitHead": "8ecf8264002298829fbce686a1bd0ad413e2e01b"
32
32
  }