handle-cli-error
Advanced tools
Comparing version 3.1.1 to 4.0.0
@@ -16,4 +16,4 @@ import process from"node:process"; | ||
exitCode, | ||
optName); | ||
optName | ||
) | ||
} | ||
@@ -28,4 +28,4 @@ }; | ||
process.exit(exitCode); | ||
}); | ||
process.exit(exitCode) | ||
}) | ||
}; | ||
@@ -40,3 +40,2 @@ | ||
export const DEFAULT_EXIT_CODE=1; | ||
//# sourceMappingURL=exit.js.map | ||
export const DEFAULT_EXIT_CODE=1; |
@@ -17,6 +17,5 @@ import normalizeException from"normalize-exception"; | ||
printError({error:errorB,silent,stack,props,colors,icon,header}); | ||
exitProcess(exitCode,timeout); | ||
exitProcess(exitCode,timeout) | ||
}; | ||
export default handleCliError; | ||
//# sourceMappingURL=main.js.map | ||
export default handleCliError; |
@@ -9,12 +9,12 @@ import isPlainObj from"is-plain-obj"; | ||
if(!isPlainObj(classes)){ | ||
handleInvalidOpts("must be a plain object",classes,optName); | ||
handleInvalidOpts("must be a plain object",classes,optName) | ||
} | ||
if(optName.length>1){ | ||
handleInvalidOpts("must not be defined",classes,optName); | ||
handleInvalidOpts("must not be defined",classes,optName) | ||
} | ||
Object.entries(classes).forEach(([className,classOpts])=>{ | ||
validateAllOpts(classOpts,[...optName,className]); | ||
}); | ||
validateAllOpts(classOpts,[...optName,className]) | ||
}) | ||
}; | ||
@@ -26,4 +26,3 @@ | ||
const classesOpts=classes[name]||classes.default||{}; | ||
return{...opts,...removeUndefined(classesOpts)}; | ||
}; | ||
//# sourceMappingURL=classes.js.map | ||
return{...opts,...removeUndefined(classesOpts)} | ||
}; |
@@ -26,3 +26,2 @@ import{excludeKeys}from"filter-obj"; | ||
const isUndefined=(key,value)=>value===undefined; | ||
//# sourceMappingURL=default.js.map | ||
const isUndefined=(key,value)=>value===undefined; |
@@ -5,4 +5,3 @@ | ||
optName.length===0?"options":`"${optName.join(".")}"`; | ||
throw new Error(`${fullOptName} ${message}: ${value}`); | ||
}; | ||
//# sourceMappingURL=invalid.js.map | ||
throw new Error(`${fullOptName} ${message}: ${value}`) | ||
}; |
@@ -12,3 +12,3 @@ import normalizeException from"normalize-exception"; | ||
try{ | ||
return safeGetOpts(opts,error); | ||
return safeGetOpts(opts,error) | ||
}catch(error_){ | ||
@@ -18,3 +18,3 @@ | ||
const errorA=normalizeException(error_); | ||
return{error:errorA,opts:INVALID_OPTS}; | ||
return{error:errorA,opts:INVALID_OPTS} | ||
} | ||
@@ -27,3 +27,3 @@ }; | ||
const optsB=applyDefaultOpts(optsA); | ||
return{error,opts:optsB}; | ||
return{error,opts:optsB} | ||
}; | ||
@@ -35,3 +35,2 @@ | ||
exitCode:INVALID_OPTS_EXIT_CODE | ||
}; | ||
//# sourceMappingURL=main.js.map | ||
}; |
@@ -14,3 +14,3 @@ import isPlainObj from"is-plain-obj"; | ||
export const validateOptions=(opts)=>{ | ||
validateAllOpts(opts,[]); | ||
validateAllOpts(opts,[]) | ||
}; | ||
@@ -20,12 +20,12 @@ | ||
if(opts===undefined){ | ||
return; | ||
return | ||
} | ||
if(!isPlainObj(opts)){ | ||
handleInvalidOpts("must be a plain object",opts,optName); | ||
handleInvalidOpts("must be a plain object",opts,optName) | ||
} | ||
Object.entries(opts).forEach(([key,optValue])=>{ | ||
validateOpt(optValue,[...optName,key]); | ||
}); | ||
validateOpt(optValue,[...optName,key]) | ||
}) | ||
}; | ||
@@ -35,3 +35,3 @@ | ||
if(optValue===undefined){ | ||
return; | ||
return | ||
} | ||
@@ -42,6 +42,6 @@ | ||
if(validator===undefined){ | ||
handleInvalidOpts("is an unknown option","",optName); | ||
handleInvalidOpts("is an unknown option","",optName) | ||
} | ||
validator(optValue,optName,validateAllOpts); | ||
validator(optValue,optName,validateAllOpts) | ||
}; | ||
@@ -51,3 +51,3 @@ | ||
if(typeof value!=="boolean"){ | ||
handleInvalidOpts("must be a boolean",value,optName); | ||
handleInvalidOpts("must be a boolean",value,optName) | ||
} | ||
@@ -66,3 +66,2 @@ }; | ||
classes:validateClasses | ||
}; | ||
//# sourceMappingURL=validate.js.map | ||
}; |
@@ -10,3 +10,3 @@ import{stderr}from"node:process"; | ||
const useColors=addStyles("red","_")!=="_"; | ||
return{addStyles,useColors}; | ||
return{addStyles,useColors} | ||
}; | ||
@@ -19,3 +19,3 @@ | ||
if(!useColors){ | ||
return line; | ||
return line | ||
} | ||
@@ -26,12 +26,12 @@ | ||
DOUBLE_QUOTED_STRING, | ||
colorizeQuotedString.bind(undefined,addStyles,"bold")). | ||
colorizeQuotedString.bind(undefined,addStyles,"bold") | ||
). | ||
replace( | ||
SINGLE_QUOTED_STRING, | ||
colorizeQuotedString.bind(undefined,addStyles,"bold")). | ||
colorizeQuotedString.bind(undefined,addStyles,"bold") | ||
). | ||
replace( | ||
BACKTICK_QUOTED_STRING, | ||
colorizeQuotedString.bind(undefined,addStyles,"italic")); | ||
colorizeQuotedString.bind(undefined,addStyles,"italic") | ||
) | ||
}; | ||
@@ -51,3 +51,2 @@ | ||
`${startQuote}${addStyles(styles,quotedString)}${endQuote}`; | ||
//# sourceMappingURL=colors.js.map | ||
`${startQuote}${addStyles(styles,quotedString)}${endQuote}`; |
@@ -10,13 +10,13 @@ import chalkString from"chalk-string"; | ||
if(typeof value!=="string"){ | ||
handleInvalidOpts("must be a string",value,optName); | ||
handleInvalidOpts("must be a string",value,optName) | ||
} | ||
if(value===""){ | ||
return; | ||
return | ||
} | ||
try{ | ||
globalAddStyles(value,""); | ||
globalAddStyles(value,"") | ||
}catch(error){ | ||
handleInvalidOpts(`must be a valid style: ${error.message}`,value,optName); | ||
handleInvalidOpts(`must be a valid style: ${error.message}`,value,optName) | ||
} | ||
@@ -34,3 +34,3 @@ }; | ||
if(header===""||!useColors){ | ||
return messageLines; | ||
return messageLines | ||
} | ||
@@ -45,3 +45,3 @@ | ||
}); | ||
return[firstMessageLineA,...messageLinesA]; | ||
return[firstMessageLineA,...messageLinesA] | ||
}; | ||
@@ -53,3 +53,3 @@ | ||
if(endIndex===-1){ | ||
return firstMessageLine; | ||
return firstMessageLine | ||
} | ||
@@ -59,3 +59,3 @@ | ||
const end=firstMessageLine.slice(endIndex); | ||
return`${addStyles(header,start)}${end}`; | ||
return`${addStyles(header,start)}${end}` | ||
}; | ||
@@ -67,3 +67,3 @@ | ||
if(endIndex!==-1){ | ||
return endIndex+1; | ||
return endIndex+1 | ||
} | ||
@@ -73,4 +73,3 @@ | ||
firstMessageLine.length: | ||
endIndex; | ||
}; | ||
//# sourceMappingURL=header.js.map | ||
endIndex | ||
}; |
@@ -11,4 +11,4 @@ import figures from"figures"; | ||
value, | ||
optName); | ||
optName | ||
) | ||
} | ||
@@ -20,8 +20,7 @@ }; | ||
if(icon===""){ | ||
return messageLines; | ||
return messageLines | ||
} | ||
const[firstMessageLine,...messageLinesA]=messageLines; | ||
return[`${figures[icon]} ${firstMessageLine}`,...messageLinesA]; | ||
}; | ||
//# sourceMappingURL=icon.js.map | ||
return[`${figures[icon]} ${firstMessageLine}`,...messageLinesA] | ||
}; |
@@ -29,3 +29,3 @@ import{inspect}from"node:util"; | ||
if(silent){ | ||
return; | ||
return | ||
} | ||
@@ -44,3 +44,3 @@ | ||
console.error(errorStringA); | ||
console.error(errorStringA) | ||
}; | ||
@@ -57,4 +57,3 @@ | ||
const errorStringA=omitStackBracket(errorString); | ||
return errorStringA; | ||
}; | ||
//# sourceMappingURL=main.js.map | ||
return errorStringA | ||
}; |
@@ -1,3 +0,1 @@ | ||
import stripAnsi from"strip-ansi"; | ||
@@ -27,3 +25,3 @@ | ||
}); | ||
return linesA.join("\n"); | ||
return linesA.join("\n") | ||
}; | ||
@@ -49,5 +47,5 @@ | ||
const messageLinesC=messageLinesB.map((line)=> | ||
colorizeLine(line,useColors,addStyles)); | ||
return[...previewLines,...messageLinesC,...stackLines]; | ||
colorizeLine(line,useColors,addStyles) | ||
); | ||
return[...previewLines,...messageLinesC,...stackLines] | ||
}; | ||
@@ -67,3 +65,3 @@ | ||
return{previewLines,messageLines:messageLinesA,stackLines}; | ||
return{previewLines,messageLines:messageLinesA,stackLines} | ||
}; | ||
@@ -81,3 +79,2 @@ | ||
const isStackLine=(line)=>stripAnsi(line).trimStart().startsWith("at "); | ||
//# sourceMappingURL=pretty.js.map | ||
const isStackLine=(line)=>stripAnsi(line).trimStart().startsWith("at "); |
@@ -10,3 +10,3 @@ | ||
if(props){ | ||
return error; | ||
return error | ||
} | ||
@@ -19,3 +19,3 @@ | ||
copyDescriptors(errorCopy,error); | ||
return errorCopy; | ||
return errorCopy | ||
}; | ||
@@ -25,4 +25,4 @@ | ||
COPIED_PROPS.forEach((propName)=>{ | ||
copyDescriptor(errorCopy,error,propName); | ||
}); | ||
copyDescriptor(errorCopy,error,propName) | ||
}) | ||
}; | ||
@@ -37,5 +37,4 @@ | ||
Object.defineProperty(errorCopy,propName,descriptor); | ||
Object.defineProperty(errorCopy,propName,descriptor) | ||
} | ||
}; | ||
//# sourceMappingURL=props.js.map | ||
}; |
@@ -9,3 +9,3 @@ import isErrorInstance from"is-error-instance"; | ||
if(!stack){ | ||
recurseObject(error,omitStackProp); | ||
recurseObject(error,omitStackProp) | ||
} | ||
@@ -20,3 +20,3 @@ }; | ||
{ | ||
return; | ||
return | ||
} | ||
@@ -26,3 +26,3 @@ | ||
delete object.stack; | ||
delete object.stack | ||
}; | ||
@@ -32,3 +32,3 @@ | ||
if(!stack){ | ||
recurseObject(error,restoreStackProp); | ||
recurseObject(error,restoreStackProp) | ||
} | ||
@@ -39,3 +39,3 @@ }; | ||
if(object[STACK_SYM]===undefined){ | ||
return; | ||
return | ||
} | ||
@@ -45,3 +45,3 @@ | ||
delete object[STACK_SYM]; | ||
delete object[STACK_SYM] | ||
}; | ||
@@ -58,3 +58,3 @@ | ||
configurable:true | ||
}); | ||
}) | ||
}; | ||
@@ -64,3 +64,3 @@ | ||
const recurseObject=(value,callFunc)=>{ | ||
recurseValue(value,callFunc,0); | ||
recurseValue(value,callFunc,0) | ||
}; | ||
@@ -74,3 +74,3 @@ | ||
{ | ||
return; | ||
return | ||
} | ||
@@ -81,4 +81,4 @@ | ||
Reflect.ownKeys(value).forEach((key)=>{ | ||
recurseValue(value[key],callFunc,depth+1); | ||
}); | ||
recurseValue(value[key],callFunc,depth+1) | ||
}) | ||
}; | ||
@@ -99,3 +99,2 @@ | ||
const STACK_BRACKET_REGEXP=/^\[([^\]]+)\]/u; | ||
//# sourceMappingURL=stack.js.map | ||
const STACK_BRACKET_REGEXP=/^\[([^\]]+)\]/u; |
@@ -12,4 +12,4 @@ import{handleInvalidOpts}from"./options/invalid.js"; | ||
timeout, | ||
optName); | ||
optName | ||
) | ||
} | ||
@@ -29,10 +29,10 @@ }; | ||
callback(); | ||
return; | ||
return | ||
} | ||
if(timeout===INFINITE_TIMEOUT){ | ||
return; | ||
return | ||
} | ||
setTimeout(callback,timeout).unref(); | ||
setTimeout(callback,timeout).unref() | ||
}; | ||
@@ -45,3 +45,2 @@ | ||
export const DEFAULT_TIMEOUT=5e3; | ||
//# sourceMappingURL=timeout.js.map | ||
export const DEFAULT_TIMEOUT=5e3; |
{ | ||
"name": "handle-cli-error", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"type": "module", | ||
@@ -53,23 +53,23 @@ "exports": { | ||
}, | ||
"dependencies": { | ||
"chalk-string": "^2.0.0", | ||
"figures": "^5.0.0", | ||
"filter-obj": "^5.1.0", | ||
"is-error-instance": "^2.0.0", | ||
"is-plain-obj": "^4.1.0", | ||
"normalize-exception": "^2.11.0", | ||
"strip-ansi": "^7.0.1" | ||
}, | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^2.0.57", | ||
"@ehmicky/dev-tasks": "^2.0.80", | ||
"@sinonjs/fake-timers": "^10.0.0", | ||
"error-serializer": "^5.1.0", | ||
"execa": "^6.1.0", | ||
"execa": "^7.1.1", | ||
"has-ansi": "^5.0.1", | ||
"sinon": "^15.0.1", | ||
"test-each": "^5.7.1" | ||
"sinon": "^15.0.4", | ||
"test-each": "^6.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=14.18.0" | ||
}, | ||
"dependencies": { | ||
"chalk-string": "^1.2.0", | ||
"figures": "^5.0.0", | ||
"filter-obj": "^5.1.0", | ||
"is-error-instance": "^1.6.0", | ||
"is-plain-obj": "^4.1.0", | ||
"normalize-exception": "^2.11.0", | ||
"strip-ansi": "^7.0.1" | ||
"node": ">=16.17.0" | ||
} | ||
} |
@@ -65,6 +65,9 @@ <picture> | ||
This package works in Node.js >=14.18.0. It is an ES module and must be loaded | ||
using | ||
This package works in Node.js >=16.17.0. | ||
This is an ES module. It must be loaded using | ||
[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), | ||
not `require()`. | ||
not `require()`. If TypeScript is used, it must be configured to | ||
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html), | ||
not CommonJS. | ||
@@ -71,0 +74,0 @@ # API |
242
26462
578
+ Addedchalk-string@2.0.0(transitive)
+ Addedcolors-option@5.0.0(transitive)
+ Addedis-error-instance@2.0.0(transitive)
- Removedchalk-string@1.2.0(transitive)
- Removedcolors-option@4.5.0(transitive)
Updatedchalk-string@^2.0.0
Updatedis-error-instance@^2.0.0