File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 11type NormalizeError < ErrorArg > = ErrorArg extends Error ? ErrorArg : Error
22
33/**
4- * Sets `error.message = newMessage`.
4+ * Sets `error.stack = stack`.
5+ * If needed, also modifies `error.message` accordingly.
56 *
6- * Returns `error`. If `error` is not an `Error` in
7- * stance, it is converted to one.
8- *
9- * If `error.stack` contains `currentMessage`, it is replaced by `newMessage`.
10- * `currentMessage` is the error message currently included in `error.stack`. It
11- * defaults to `error.message`, which is usually best.
7+ * Returns `error`. If `error` is not an `Error` instance, it is converted to
8+ * one.
129 *
1310 * @example
1411 * ```js
1512 * const error = new Error('one')
16- * console.log(error.message) // 'one'
1713 * console.log(error.stack) // 'Error: one ...'
14+ * console.log(error.message) // 'one'
1815 *
19- * setErrorStack(error, 'two')
20- * console.log(error.message) // 'two'
16+ * setErrorStack(error, error.stack.replace('one', 'two'))
2117 * console.log(error.stack) // 'Error: two ...'
18+ * console.log(error.message) // 'two'
2219 * ```
2320 */
2421export default function setErrorStack < ErrorArg > (
You can’t perform that action at this time.
0 commit comments