Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 16, 2019
1 parent 0a60124 commit a1d858d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ export const streamError = function(stream, error, opts) {
// are kept. They are not printed though, as error message should be enough.
const createError = function(error, opts) {
const errorA = error instanceof Error ? error : new Error(error)
fixStack(errorA)
return new PluginError({ ...PLUGIN_ERROR_OPTS, ...opts, error: errorA })
const stack = getStack(errorA)
return new PluginError({
...PLUGIN_ERROR_OPTS,
...opts,
error: errorA,
stack,
})
}

const PLUGIN_ERROR_OPTS = {
Expand All @@ -32,9 +37,8 @@ const PLUGIN_ERROR_OPTS = {

// `plugin-error` repeats the error message by printing both `error.message`
// and the first line of `error.stack`. We remove that last one.
const fixStack = function(error) {
// eslint-disable-next-line no-param-reassign, fp/no-mutation
error.stack = error.stack
const getStack = function({ stack }) {
return stack
.split('\n')
.slice(1)
.join('\n')
Expand Down

0 comments on commit a1d858d

Please sign in to comment.