beautiful-error
Version:
💣 Prettify error messages and stacks 💥
34 lines (23 loc) • 608 B
JavaScript
import{setNonEnumProp}from"./utils.js";
export const pickChildErrors=(error)=>{
const{cause,errors}=error;
delete error.cause;
delete error.errors;
return{cause,errors}
};
export const restoreChildErrors=(error,cause,errors)=>{
if(cause!==undefined){
setNonEnumProp(error,"cause",cause)
}
if(error!==undefined){
setNonEnumProp(error,"errors",errors)
}
};
export const indentError=(errorString,depth)=>
errorString.
split("\n").
map((line)=>indentChildLine(line,depth)).
join("\n");
const indentChildLine=(line,depth)=>
depth===0?line:`${" ".repeat(depth*INDENT_SIZE)}${line}`;
const INDENT_SIZE=4;