import * as PQP from "@microsoft/powerquery-parser" ; export function formatError ( error ) { return JSON . stringify ( formatErrorMetadata ( error ) , null , 4 ) ; } export interface FormatErrorMetadata { readonly maybeChild : FormatErrorMetadata | undefined ; readonly maybeTopOfStack : string | undefined ; readonly message : string | undefined ; readonly name : string ; } function formatErrorMetadata ( error ) { let maybeChild ; if ( error instanceof PQP . CommonError . CommonError || error instanceof PQP . Lexer . LexError . LexError || error instanceof PQP . Parser . ParseError . ParseError ) { maybeChild = formatErrorMetadata ( error . innerError ) ; } const maybeSplitLines = error . stack ?. split ( "\n" ) ; return { maybeChild , maybeTopOfStack : maybeSplitLines !== undefined ? maybeSplitLines . slice ( 0 , 4 ) . join ( "\n" ) : undefined , message : error . message , name : error . constructor . name , } ; }