Skip to content

Refactor stack trace cleaning #827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/build/src/error/clean_stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const stripAnsi = require('strip-ansi')
// Keep non stack trace lines as is.
// We do not use libraries that patch `Error.prepareStackTrace()` because they
// tend to create issues.
const cleanStacks = function(string) {
const cleanStacks = function(string, rawStack) {
// Internal errors / bugs keep their full stack trace
if (rawStack || string === undefined) {
return string
}

return String(string)
.split('\n')
.reduce(cleanStackLine, '')
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/error/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ const CLEANED_ERROR_PROPS = [INFO_SYM, 'requireStack']

// Retrieve body to print in logs
const getBody = function({
typeInfo: { stackType, getLocation, showErrorProps },
typeInfo: { stackType, getLocation, showErrorProps, rawStack },
message,
stack,
errorProps,
location = {},
plugin = {},
}) {
const { message: messageA, stack: stackA } = getStackInfo({ message, stack, stackType })
const { message: messageA, stack: stackA } = getStackInfo({ message, stack, stackType, rawStack })
const messageBlock = { name: 'Error message', value: messageA }
const pluginBlock = getPluginBlock(plugin)
const locationBlock = getLocationBlock({ stack: stackA, location, getLocation })
Expand Down
29 changes: 12 additions & 17 deletions packages/build/src/error/stack.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
const { cleanStacks } = require('./clean_stack')

// Retrieve the stack trace
const getStackInfo = function({ message, stack, stackType }) {
const getStackInfo = function({ message, stack, stackType, rawStack }) {
const { message: messageA, stack: stackA } = splitStackInfo({ message, stack, stackType })
const stackB = cleanStacks(stackA, rawStack)
return { message: messageA, stack: stackB }
}

const splitStackInfo = function({ message, stack, stackType }) {
// Some errors should not show any stack trace
if (stackType === 'none') {
return { message }
}

// Some errors should show `error.stack` as is, without cleaning it
if (stackType === 'stack') {
return splitStack(stack)
}

return splitStackInfo(message)
}

// Some errors have the stack trace inside `error.message` instead of
// `error.stack` due to IPC
const splitStackInfo = function(string) {
const { message, stack } = splitStack(string)
if (stack === undefined) {
return { message }
// Some errors have their stack trace inside `error.message` instead of
// `error.stack` due to IPC
if (stackType === 'message') {
return splitStack(message)
}

const stackA = cleanStacks(stack)
return { message, stack: stackA }
return splitStack(stack)
}

const splitStack = function(string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/error/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const TYPES = {
pluginLoad: { header: 'Build failed', stackType: 'message', getLocation: getPluginLoadLocation },
shellCommand: { header: 'Build failed', stackType: 'message', getLocation: getShellCommandLocation },
pluginCommand: { header: 'Build failed', stackType: 'message', getLocation: getPluginCommandLocation },
internalError: { header: 'Internal error', stackType: 'stack', showErrorProps: true },
internalError: { header: 'Internal error', stackType: 'stack', showErrorProps: true, rawStack: true },
}
// When no error type matches, it's an uncaught exception, i.e. a bug
const DEFAULT_TYPE = 'internalError'
Expand Down
Binary file modified packages/build/tests/cache/main/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/config/cwd/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/config/load/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/config/normalize/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/config/template/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/config/validate/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/core/cli/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/core/commands/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/core/lifecycle/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/error/plugin_load/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/error/stack/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/api/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/config/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/constants/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/duplicate/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/env/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/functions/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/install/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/load/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/plugins/validate/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/utils/cache/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/utils/git/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/utils/load/snapshots/tests.js.snap
Binary file not shown.
Binary file modified packages/build/tests/utils/run/snapshots/tests.js.snap
Binary file not shown.