INNER CODE UNIT · TypeScript
getErrorMessage
niklashigi/apk-mitm · src/cli.ts:206
function getErrorMessage(error: PatchingError, { tmpDir }: { tmpDir: string }) {
// User errors can be shown without a stack trace
if (error instanceof UserError) return error.message
// Errors from commands can also be shown without a stack trace
if (error.all) return formatCommandError(error.all, { tmpDir })
return error.stack
}
function formatCommandError(error: string, { tmpDir }: { tmpDir: string }) {
return (
error
// Replace mentions of the (sometimes very long) temporary directory path
.replace(new RegExp(tmpDir, 'g'), chalk`{bold <tmp_dir>}`)
// Highlight (usually relevant) warning lines in Apktool output
.replace(/^W: .+$/gm, line => chalk`{yellow ${line}}`)
// De-emphasize Apktool info lines