fix(xo-cli): extract ws error message

Fixes #6022
This commit is contained in:
Julien Fontanet 2022-07-21 12:36:58 +02:00
parent 2fb27b26cd
commit af4cc1f574
2 changed files with 24 additions and 13 deletions

View File

@ -30,6 +30,7 @@
<!--packages-start-->
- @vates/async-each major
- xo-cli patch
- xo-web patch
<!--packages-end-->

View File

@ -247,7 +247,7 @@ $name v$version
const COMMANDS = { __proto__: null }
function main(args) {
async function main(args) {
if (!args || !args.length || args[0] === '-h') {
return help()
}
@ -259,22 +259,32 @@ function main(args) {
return match[1].toUpperCase()
})
if (fnName in COMMANDS) {
return COMMANDS[fnName](args.slice(1))
}
return COMMANDS.call(args).catch(error => {
if (!(error != null && error.code === 10 && 'errors' in error.data)) {
throw error
try {
if (fnName in COMMANDS) {
return await COMMANDS[fnName](args.slice(1))
}
const lines = [error.message]
const { errors } = error.data
errors.forEach(error => {
lines.push(` property ${error.property}: ${error.message}`)
return await COMMANDS.call(args).catch(error => {
if (!(error != null && error.code === 10 && 'errors' in error.data)) {
throw error
}
const lines = [error.message]
const { errors } = error.data
errors.forEach(error => {
lines.push(` property ${error.property}: ${error.message}`)
})
throw lines.join('\n')
})
throw lines.join('\n')
})
} catch (error) {
// `promise-toolbox/fromEvent` uses `addEventListener` by default wich makes
// `ws/WebSocket` (used by `xo-lib`) emit DOM `Event` objects which are not
// correctly displayed by `exec-promise`.
//
// Extracts the original error for a better display.
throw 'error' in error ? error.error : error
}
}
// -------------------------------------------------------------------