handle-cli-error
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -7,3 +7,3 @@ import process from"node:process"; | ||
export const validateExitCode=function(exitCode,optName){ | ||
export const validateExitCode=(exitCode,optName)=>{ | ||
if( | ||
@@ -24,3 +24,3 @@ !Number.isInteger(exitCode)|| | ||
export const exitProcess=function(exitCode,timeout){ | ||
export const exitProcess=(exitCode,timeout)=>{ | ||
process.exitCode=exitCode; | ||
@@ -27,0 +27,0 @@ waitForTimeout(timeout,()=>{ |
@@ -10,11 +10,13 @@ import normalizeException from"normalize-exception"; | ||
export default function handleCliError(error,opts){ | ||
const handleCliError=(error,opts)=>{ | ||
const errorA=normalizeException(error); | ||
const{ | ||
error:errorB, | ||
opts:{silent,stack,props,colors,icon,header,exitCode,timeout}}= | ||
getOpts(opts,errorA); | ||
opts:{silent,stack,props,colors,icon,header,exitCode,timeout} | ||
}=getOpts(opts,errorA); | ||
printError({error:errorB,silent,stack,props,colors,icon,header}); | ||
exitProcess(exitCode,timeout); | ||
} | ||
}; | ||
export default handleCliError; | ||
//# sourceMappingURL=main.js.map |
@@ -7,3 +7,3 @@ import isPlainObj from"is-plain-obj"; | ||
export const validateClasses=function(classes,optName,validateAllOpts){ | ||
export const validateClasses=(classes,optName,validateAllOpts)=>{ | ||
if(!isPlainObj(classes)){ | ||
@@ -24,6 +24,3 @@ handleInvalidOpts("must be a plain object",classes,optName); | ||
export const applyClassesOpts=function( | ||
{name}, | ||
{classes={},...opts}={}) | ||
{ | ||
export const applyClassesOpts=({name},{classes={},...opts}={})=>{ | ||
const classesOpts=classes[name]||classes.default||{}; | ||
@@ -30,0 +27,0 @@ return{...opts,...removeUndefined(classesOpts)}; |
@@ -7,5 +7,6 @@ import{excludeKeys}from"filter-obj"; | ||
export const applyDefaultOpts=function(opts){ | ||
return{...DEFAULT_OPTS,...removeUndefined(opts)}; | ||
}; | ||
export const applyDefaultOpts=(opts)=>({ | ||
...DEFAULT_OPTS, | ||
...removeUndefined(opts) | ||
}); | ||
@@ -20,13 +21,9 @@ | ||
exitCode:DEFAULT_EXIT_CODE, | ||
timeout:DEFAULT_TIMEOUT}; | ||
timeout:DEFAULT_TIMEOUT | ||
}; | ||
export const removeUndefined=(object)=>excludeKeys(object,isUndefined); | ||
export const removeUndefined=function(object){ | ||
return excludeKeys(object,isUndefined); | ||
}; | ||
const isUndefined=function(key,value){ | ||
return value===undefined; | ||
}; | ||
const isUndefined=(key,value)=>value===undefined; | ||
//# sourceMappingURL=default.js.map |
export const handleInvalidOpts=function(message,value,optName){ | ||
export const handleInvalidOpts=(message,value,optName)=>{ | ||
const fullOptName= | ||
@@ -4,0 +4,0 @@ optName.length===0?"options":`"${optName.join(".")}"`; |
@@ -10,3 +10,3 @@ import normalizeException from"normalize-exception"; | ||
export const getOpts=function(opts,error){ | ||
export const getOpts=(opts,error)=>{ | ||
try{ | ||
@@ -22,3 +22,3 @@ return safeGetOpts(opts,error); | ||
const safeGetOpts=function(opts,error){ | ||
const safeGetOpts=(opts,error)=>{ | ||
validateOptions(opts); | ||
@@ -33,3 +33,4 @@ const optsA=applyClassesOpts(error,opts); | ||
...DEFAULT_OPTS, | ||
exitCode:INVALID_OPTS_EXIT_CODE}; | ||
exitCode:INVALID_OPTS_EXIT_CODE | ||
}; | ||
//# sourceMappingURL=main.js.map |
@@ -13,7 +13,7 @@ import isPlainObj from"is-plain-obj"; | ||
export const validateOptions=function(opts){ | ||
export const validateOptions=(opts)=>{ | ||
validateAllOpts(opts,[]); | ||
}; | ||
const validateAllOpts=function(opts,optName){ | ||
const validateAllOpts=(opts,optName)=>{ | ||
if(opts===undefined){ | ||
@@ -32,3 +32,3 @@ return; | ||
const validateOpt=function(optValue,optName){ | ||
const validateOpt=(optValue,optName)=>{ | ||
if(optValue===undefined){ | ||
@@ -47,3 +47,3 @@ return; | ||
const validateBooleanOpt=function(value,optName){ | ||
const validateBooleanOpt=(value,optName)=>{ | ||
if(typeof value!=="boolean"){ | ||
@@ -63,3 +63,4 @@ handleInvalidOpts("must be a boolean",value,optName); | ||
timeout:validateTimeout, | ||
classes:validateClasses}; | ||
classes:validateClasses | ||
}; | ||
//# sourceMappingURL=validate.js.map |
@@ -7,3 +7,3 @@ import{stderr}from"node:process"; | ||
export const getColors=function(colors){ | ||
export const getColors=(colors)=>{ | ||
const addStyles=chalkString({colors,stream:stderr}); | ||
@@ -17,3 +17,3 @@ const useColors=addStyles("red","_")!=="_"; | ||
export const colorizeLine=function(line,useColors,addStyles){ | ||
export const colorizeLine=(line,useColors,addStyles)=>{ | ||
if(!useColors){ | ||
@@ -42,4 +42,3 @@ return line; | ||
const colorizeQuotedString=function( | ||
const colorizeQuotedString=( | ||
addStyles, | ||
@@ -50,6 +49,5 @@ styles, | ||
quotedString, | ||
endQuote) | ||
{ | ||
return`${startQuote}${addStyles(styles,quotedString)}${endQuote}`; | ||
}; | ||
endQuote)=> | ||
`${startQuote}${addStyles(styles,quotedString)}${endQuote}`; | ||
//# sourceMappingURL=colors.js.map |
@@ -8,3 +8,3 @@ import chalkString from"chalk-string"; | ||
export const validateHeader=function(value,optName){ | ||
export const validateHeader=(value,optName)=>{ | ||
if(typeof value!=="string"){ | ||
@@ -26,3 +26,3 @@ handleInvalidOpts("must be a string",value,optName); | ||
export const applyHeader=function({ | ||
export const applyHeader=({ | ||
messageLines, | ||
@@ -32,4 +32,4 @@ header, | ||
addStyles, | ||
error}) | ||
{ | ||
error | ||
})=>{ | ||
if(header===""||!useColors){ | ||
@@ -44,13 +44,8 @@ return messageLines; | ||
addStyles, | ||
error}); | ||
error | ||
}); | ||
return[firstMessageLineA,...messageLinesA]; | ||
}; | ||
const applyHeaderLine=function({ | ||
firstMessageLine, | ||
header, | ||
addStyles, | ||
error}) | ||
{ | ||
const applyHeaderLine=({firstMessageLine,header,addStyles,error})=>{ | ||
const endIndex=getEndIndex(firstMessageLine,error); | ||
@@ -67,3 +62,3 @@ | ||
const getEndIndex=function(firstMessageLine,error){ | ||
const getEndIndex=(firstMessageLine,error)=>{ | ||
const endIndex=firstMessageLine.indexOf(":"); | ||
@@ -70,0 +65,0 @@ |
@@ -6,3 +6,3 @@ import figures from"figures"; | ||
export const validateIcon=function(value,optName){ | ||
export const validateIcon=(value,optName)=>{ | ||
if(value!==""&&figures[value]===undefined){ | ||
@@ -18,3 +18,3 @@ handleInvalidOpts( | ||
export const addIcon=function(messageLines,icon){ | ||
export const addIcon=(messageLines,icon)=>{ | ||
if(icon===""){ | ||
@@ -21,0 +21,0 @@ return messageLines; |
@@ -19,3 +19,3 @@ import{inspect}from"node:util"; | ||
export const printError=function({ | ||
export const printError=({ | ||
error, | ||
@@ -27,4 +27,4 @@ silent, | ||
icon, | ||
header}) | ||
{ | ||
header | ||
})=>{ | ||
if(silent){ | ||
@@ -42,9 +42,9 @@ return; | ||
icon, | ||
header}); | ||
header | ||
}); | ||
console.error(errorStringA); | ||
}; | ||
const serializeError=function({error,stack,props,useColors}){ | ||
const serializeError=({error,stack,props,useColors})=>{ | ||
const errorA=omitProps(error,props); | ||
@@ -54,4 +54,4 @@ omitStack(errorA,stack); | ||
colors:useColors, | ||
depth:PRINT_MAX_DEPTH}); | ||
depth:PRINT_MAX_DEPTH | ||
}); | ||
restoreStack(errorA,stack); | ||
@@ -58,0 +58,0 @@ const errorStringA=omitStackBracket(errorString); |
@@ -10,3 +10,3 @@ | ||
export const prettifyError=function({ | ||
export const prettifyError=({ | ||
error, | ||
@@ -17,4 +17,4 @@ errorString, | ||
icon, | ||
header}) | ||
{ | ||
header | ||
})=>{ | ||
const lines=errorString.split("\n"); | ||
@@ -27,8 +27,8 @@ const linesA=prettifyLines({ | ||
icon, | ||
header}); | ||
header | ||
}); | ||
return linesA.join("\n"); | ||
}; | ||
const prettifyLines=function({ | ||
const prettifyLines=({ | ||
error, | ||
@@ -39,4 +39,4 @@ lines, | ||
icon, | ||
header}) | ||
{ | ||
header | ||
})=>{ | ||
const{previewLines,messageLines,stackLines}=splitStack(lines,error); | ||
@@ -49,4 +49,4 @@ const messageLinesA=addIcon(messageLines,icon); | ||
addStyles, | ||
error}); | ||
error | ||
}); | ||
const messageLinesC=messageLinesB.map((line)=> | ||
@@ -58,3 +58,3 @@ colorizeLine(line,useColors,addStyles)); | ||
const splitStack=function(lines,error){ | ||
const splitStack=(lines,error)=>{ | ||
const messageLineIndex=lines.findIndex((line)=>isMessageLine(line,error)); | ||
@@ -78,14 +78,9 @@ const messageLineIndexA=messageLineIndex===-1?0:messageLineIndex; | ||
const isMessageLine=function(line,error){ | ||
return( | ||
const isMessageLine=(line,error)=> | ||
line===error.name|| | ||
line.startsWith(`${error.name}: `)|| | ||
line.startsWith(`${error.constructor.name} [`)); | ||
line.startsWith(`${error.constructor.name} [`); | ||
}; | ||
const isStackLine=function(line){ | ||
return stripAnsi(line).trimStart().startsWith("at "); | ||
}; | ||
const isStackLine=(line)=>stripAnsi(line).trimStart().startsWith("at "); | ||
//# sourceMappingURL=pretty.js.map |
@@ -8,3 +8,3 @@ | ||
export const omitProps=function(error,props){ | ||
export const omitProps=(error,props)=>{ | ||
if(props){ | ||
@@ -14,2 +14,3 @@ return error; | ||
const errorCopy=new Error(""); | ||
@@ -22,3 +23,3 @@ | ||
const copyDescriptors=function(errorCopy,error){ | ||
const copyDescriptors=(errorCopy,error)=>{ | ||
COPIED_PROPS.forEach((propName)=>{ | ||
@@ -31,3 +32,3 @@ copyDescriptor(errorCopy,error,propName); | ||
const copyDescriptor=function(errorCopy,error,propName){ | ||
const copyDescriptor=(errorCopy,error,propName)=>{ | ||
const descriptor=Object.getOwnPropertyDescriptor(error,propName); | ||
@@ -34,0 +35,0 @@ |
@@ -7,3 +7,3 @@ import isErrorInstance from"is-error-instance"; | ||
export const omitStack=function(error,stack){ | ||
export const omitStack=(error,stack)=>{ | ||
if(!stack){ | ||
@@ -14,3 +14,3 @@ recurseObject(error,omitStackProp); | ||
const omitStackProp=function(object){ | ||
const omitStackProp=(object)=>{ | ||
if( | ||
@@ -29,3 +29,3 @@ !isErrorInstance(object)|| | ||
export const restoreStack=function(error,stack){ | ||
export const restoreStack=(error,stack)=>{ | ||
if(!stack){ | ||
@@ -36,3 +36,3 @@ recurseObject(error,restoreStackProp); | ||
const restoreStackProp=function(object){ | ||
const restoreStackProp=(object)=>{ | ||
if(object[STACK_SYM]===undefined){ | ||
@@ -49,3 +49,3 @@ return; | ||
const setNonEnumProp=function(object,propName,value){ | ||
const setNonEnumProp=(object,propName,value)=>{ | ||
@@ -56,12 +56,12 @@ Object.defineProperty(object,propName,{ | ||
writable:true, | ||
configurable:true}); | ||
configurable:true | ||
}); | ||
}; | ||
const recurseObject=function(value,callFunc){ | ||
const recurseObject=(value,callFunc)=>{ | ||
recurseValue(value,callFunc,0); | ||
}; | ||
const recurseValue=function(value,callFunc,depth){ | ||
const recurseValue=(value,callFunc,depth)=>{ | ||
if( | ||
@@ -92,7 +92,6 @@ typeof value!=="object"|| | ||
export const omitStackBracket=function(errorString){ | ||
return errorString.replace(STACK_BRACKET_REGEXP,"$1"); | ||
}; | ||
export const omitStackBracket=(errorString)=> | ||
errorString.replace(STACK_BRACKET_REGEXP,"$1"); | ||
const STACK_BRACKET_REGEXP=/^\[([^\]]+)\]/u; | ||
//# sourceMappingURL=stack.js.map |
import{handleInvalidOpts}from"./options/invalid.js"; | ||
export const validateTimeout=function(timeout,optName){ | ||
export const validateTimeout=(timeout,optName)=>{ | ||
if( | ||
@@ -17,5 +17,4 @@ (!Number.isInteger(timeout)||timeout<=0)&& | ||
const isSpecialTimeout=function(timeout){ | ||
return timeout===INFINITE_TIMEOUT||timeout===NO_TIMEOUT; | ||
}; | ||
const isSpecialTimeout=(timeout)=> | ||
timeout===INFINITE_TIMEOUT||timeout===NO_TIMEOUT; | ||
@@ -26,3 +25,3 @@ | ||
export const waitForTimeout=function(timeout,callback){ | ||
export const waitForTimeout=(timeout,callback)=>{ | ||
if(timeout===NO_TIMEOUT){ | ||
@@ -29,0 +28,0 @@ |
{ | ||
"name": "handle-cli-error", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"type": "module", | ||
"exports": { | ||
"types": "./build/types/main.d.ts", | ||
"types": "./build/src/main.d.ts", | ||
"default": "./build/src/main.js" | ||
}, | ||
"main": "./build/src/main.js", | ||
"types": "./build/types/main.d.ts", | ||
"types": "./build/src/main.d.ts", | ||
"files": [ | ||
"build/src/**/*.{js,json}", | ||
"build/types/**/*.d.ts" | ||
"build/src/**/*.{js,json,d.ts}", | ||
"!build/src/**/*.test.js", | ||
"!build/src/{helpers,fixtures}" | ||
], | ||
@@ -50,13 +51,12 @@ "sideEffects": false, | ||
"directories": { | ||
"lib": "src", | ||
"test": "test" | ||
"lib": "src" | ||
}, | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^1.0.102", | ||
"@sinonjs/fake-timers": "^9.1.2", | ||
"error-serializer": "^3.7.0", | ||
"@ehmicky/dev-tasks": "^2.0.57", | ||
"@sinonjs/fake-timers": "^10.0.0", | ||
"error-serializer": "^5.1.0", | ||
"execa": "^6.1.0", | ||
"has-ansi": "^5.0.1", | ||
"sinon": "^14.0.1", | ||
"test-each": "^5.5.0" | ||
"sinon": "^15.0.1", | ||
"test-each": "^5.7.1" | ||
}, | ||
@@ -70,3 +70,3 @@ "engines": { | ||
"filter-obj": "^5.1.0", | ||
"is-error-instance": "^1.3.0", | ||
"is-error-instance": "^1.6.0", | ||
"is-plain-obj": "^4.1.0", | ||
@@ -73,0 +73,0 @@ "normalize-exception": "^2.11.0", |
@@ -7,5 +7,5 @@ <picture> | ||
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/handle-cli-error) | ||
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/types/main.d.ts) | ||
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts) | ||
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/handle-cli-error) | ||
[![Twitter](https://img.shields.io/badge/-Twitter-808080.svg?logo=twitter&colorA=404040)](https://twitter.com/intent/follow?screen_name=ehmicky) | ||
[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky) | ||
[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky) | ||
@@ -37,3 +37,3 @@ | ||
const cliMain = function () { | ||
const cliMain = () => { | ||
try { | ||
@@ -174,4 +174,4 @@ // ... | ||
- [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors | ||
like it's 2022 🔮 | ||
- [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors in | ||
a simple, stable, consistent way | ||
- [`modern-errors-cli`](https://github.com/ehmicky/modern-errors-cli): Handle | ||
@@ -195,4 +195,8 @@ errors in CLI modules | ||
update an error's message | ||
- [`wrap-error-message`](https://github.com/ehmicky/wrap-error-message): | ||
Properly wrap an error's message | ||
- [`set-error-props`](https://github.com/ehmicky/set-error-props): Properly | ||
update an error's properties | ||
- [`set-error-stack`](https://github.com/ehmicky/set-error-stack): Properly | ||
update an error's stack | ||
- [`error-cause-polyfill`](https://github.com/ehmicky/error-cause-polyfill): | ||
@@ -202,2 +206,6 @@ Polyfill `error.cause` | ||
some ❤ to Node.js process errors | ||
- [`error-http-response`](https://github.com/ehmicky/error-http-response): | ||
Create HTTP error responses | ||
- [`winston-error-format`](https://github.com/ehmicky/winston-error-format): Log | ||
errors with Winston | ||
@@ -233,4 +241,4 @@ # Credits | ||
<!-- | ||
<table><tr><td align="center"><a href="https://twitter.com/ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/handle-cli-error/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/handle-cli-error/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table> | ||
<table><tr><td align="center"><a href="https://fosstodon.org/@ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/handle-cli-error/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/handle-cli-error/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table> | ||
--> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> |
26901
239
586
Updatedis-error-instance@^1.6.0