import path from 'path' ; export const MODULE_ROOT = path . resolve ( __dirname , '../../' ) ; param err param stack export function stringifyStackTrace ( err , stack ) { const callSiteStrings = stack . map ( callSite => { return `    at ${ callSite }` ; } ) . join ( '\n' ) ; const stackTrace = `${ err . name }: ${ err . message }\n${ callSiteStrings }` ; return stackTrace ; } param stack export function filterCallSites ( stack ) { let indexOfFirstInternalCallSite = stack . findIndex ( callSite => callSite . getFileName ( ) ?. includes ( MODULE_ROOT ) ) ; indexOfFirstInternalCallSite = indexOfFirstInternalCallSite === - 1 ? stack . length : indexOfFirstInternalCallSite ; return stack . slice ( 0 , indexOfFirstInternalCallSite ) ; } param err param stack export function formatStackTraceWithInternals ( err , stack ) { const filteredStack = filterCallSites ( stack ) ; const stackTraceWithoutInternals = stringifyStackTrace ( err , filteredStack ) ; if ( filteredStack . length === stack . length ) { return stackTraceWithoutInternals ; } return `${ stackTraceWithoutInternals }\n    at [Twilio Dev Server internals]` ; }