Skip to content

Commit d14cac6

Browse files
committed
Add beautiful-error
1 parent 655d9b5 commit d14cac6

5 files changed

Lines changed: 28 additions & 44 deletions

File tree

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"lib": "src"
5555
},
5656
"dependencies": {
57+
"beautiful-error": "^1.0.0",
5758
"chalk-string": "^3.0.1",
5859
"figures": "^6.0.1",
5960
"filter-obj": "^6.1.0",

src/options/validate.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import isPlainObj from 'is-plain-obj'
22

33
import { validateExitCode } from '../exit.js'
4-
import { validateHeader } from '../print/header.js'
5-
import { validateIcon } from '../print/icon.js'
64
import { validateTimeout } from '../timeout.js'
75

86
import { validateClasses } from './classes.js'
@@ -29,7 +27,7 @@ const validateAllOpts = (opts, optName) => {
2927
}
3028

3129
const validateOpt = (optValue, optName) => {
32-
if (optValue === undefined) {
30+
if (optValue === undefined || BEAUTIFUL_ERROR_OPTS.has(optName)) {
3331
return
3432
}
3533

@@ -50,12 +48,15 @@ const validateBooleanOpt = (value, optName) => {
5048

5149
const VALIDATORS = {
5250
silent: validateBooleanOpt,
53-
stack: validateBooleanOpt,
54-
props: validateBooleanOpt,
55-
colors: validateBooleanOpt,
56-
icon: validateIcon,
57-
header: validateHeader,
5851
exitCode: validateExitCode,
5952
timeout: validateTimeout,
6053
classes: validateClasses,
6154
}
55+
56+
const BEAUTIFUL_ERROR_OPTS = new Set([
57+
'stack',
58+
'props',
59+
'colors',
60+
'icon',
61+
'header',
62+
])

src/print/header.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,3 @@
1-
import chalkString from 'chalk-string'
2-
3-
import { handleInvalidOpts } from '../options/invalid.js'
4-
5-
const globalAddStyles = chalkString({ colors: true })
6-
7-
// Validate `header` option
8-
export const validateHeader = (value, optName) => {
9-
if (typeof value !== 'string') {
10-
handleInvalidOpts('must be a string', value, optName)
11-
}
12-
13-
if (value === '') {
14-
return
15-
}
16-
17-
try {
18-
globalAddStyles(value, '')
19-
} catch (error) {
20-
handleInvalidOpts(`must be a valid style: ${error.message}`, value, optName)
21-
}
22-
}
23-
241
// Apply `header` option to colorize the error's icon and name
252
export const applyHeader = ({
263
messageLines,

src/print/icon.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
import figures from 'figures'
22

3-
import { handleInvalidOpts } from '../options/invalid.js'
4-
5-
// Validate `icon` option
6-
export const validateIcon = (value, optName) => {
7-
if (value !== '' && figures[value] === undefined) {
8-
handleInvalidOpts(
9-
`must be an icon name like "cross", "info" or "warning"`,
10-
value,
11-
optName,
12-
)
13-
}
14-
}
15-
163
// Adds `icon` option before the error name
174
export const addIcon = (messageLines, icon) => {
185
if (icon === '') {

0 commit comments

Comments
 (0)