Skip to content

Commit

Permalink
Fix stack with runner errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Nov 6, 2022
1 parent 7becf96 commit c0b9096
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 29 deletions.
22 changes: 11 additions & 11 deletions src/error/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ export const PluginError = AnyError.subclass('PluginError', {
cli: { exitCode: 2, header: 'magenta bold', icon: 'star' },
})

// User aborting the benchmark
export const StopError = AnyError.subclass('StopError', {
cli: { exitCode: 3, header: 'gray bold', icon: 'hamburger' },
})

// Invalid tasks or tasks file
export const UserCodeError = AnyError.subclass('UserCodeError', {
cli: { exitCode: 4, header: 'yellow bold', icon: 'pointer' },
// Tasks failed to load or run
export const TaskError = AnyError.subclass('TaskError', {
cli: { exitCode: 3, header: 'yellow bold', icon: 'pointer' },
})

// Invalid options
// Invalid syntax with options or tasks file
export const UserError = AnyError.subclass('UserError', {
cli: { exitCode: 5, header: 'yellow bold', icon: 'warning' },
cli: { exitCode: 4, header: 'yellow bold', icon: 'warning', stack: false },
})

// `limit` option threshold was reached
export const LimitError = AnyError.subclass('LimitError', {
cli: { exitCode: 6, header: 'cyan bold', icon: 'triangleDown' },
cli: { exitCode: 5, header: 'cyan bold', icon: 'triangleDown', stack: false },
})

// User aborting the benchmark
export const StopError = AnyError.subclass('StopError', {
cli: { exitCode: 6, header: 'gray bold', icon: 'hamburger', stack: false },
})
24 changes: 9 additions & 15 deletions src/run/process/task_error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isErrorInstance from 'is-error-instance'

import { PluginError, UserError, UserCodeError } from '../../error/main.js'
import { PluginError, UserError, TaskError } from '../../error/main.js'
import { AnyError } from '../../runners/common/error.js'

// When a task throws during any stage, we propagate the error and fail the
Expand All @@ -14,8 +14,8 @@ export const throwOnTaskError = function ({ error: errorObject }) {
}

const error = AnyError.parse(errorObject)
const { ErrorClass, prefix, stack } = ERROR_MAP[getName(error)]
throw new ErrorClass(prefix, { cause: error, cli: { stack } })
const { ErrorClass, prefix } = ERROR_MAP[getName(error)]
throw new ErrorClass(prefix, { cause: error })
}

const getName = function (error) {
Expand All @@ -31,32 +31,26 @@ const ERROR_MAP = {
UnknownError: {
ErrorClass: PluginError,
prefix: 'Runner internal bug.',
stack: true,
},
IpcSerializationError: {
ErrorClass: PluginError,
prefix: 'Serialization error.',
stack: true,
},
TasksLoadError: {
ErrorClass: UserCodeError,
ErrorClass: TaskError,
prefix: 'Could not load the tasks file.',
stack: true,
},
TasksSyntaxError: {
ErrorClass: UserCodeError,
prefix: 'Syntax error in the tasks file.',
stack: false,
},
TasksRunError: {
ErrorClass: UserCodeError,
ErrorClass: TaskError,
prefix: 'Could not run the task.',
stack: true,
},
TasksSyntaxError: {
ErrorClass: UserError,
prefix: 'Syntax error in the tasks file.',
},
ConfigError: {
ErrorClass: UserError,
prefix: 'Runner configuration error.',
stack: false,
},
}

Expand Down
6 changes: 3 additions & 3 deletions src/runners/common/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export const IpcSerializationError = AnyError.subclass('IpcSerializationError')
// Tasks file throws when loading
export const TasksLoadError = AnyError.subclass('TasksLoadError')

// Tasks file has invalid syntax, e.g. exports invalid fields
export const TasksSyntaxError = AnyError.subclass('TasksSyntaxError')

// Tasks throws when running
export const TasksRunError = AnyError.subclass('TasksRunError')

// Tasks file has invalid syntax, e.g. exports invalid fields
export const TasksSyntaxError = AnyError.subclass('TasksSyntaxError')

// Invalid runner config
export const ConfigError = AnyError.subclass('ConfigError')

0 comments on commit c0b9096

Please sign in to comment.