UNPKG

handle-cli-error

Version:

💣 Error handler for CLI applications 💥

34 lines (23 loc) • 696 B
import beautifulError from"beautiful-error"; import normalizeException from"normalize-exception"; import{exitProcess}from"./exit.js"; import{getOpts}from"./options/main.js"; export{validateOptions}from"./options/validate.js"; const handleCliError=(error,opts)=>{ const errorA=normalizeException(error); const{ error:errorB, opts:{silent,exitCode,timeout,log}, beautifulErrorOpts }=getOpts(errorA,opts); printError({error:errorB,silent,log,beautifulErrorOpts}); exitProcess(exitCode,timeout) }; const printError=({error,silent,log,beautifulErrorOpts})=>{ if(silent){ return } const errorString=beautifulError(error,beautifulErrorOpts); log(errorString) }; export default handleCliError;