Make error output easier to parse

This commit is contained in:
Niklas Higi
2020-06-28 23:07:39 +02:00
parent f6d41e90ea
commit bf62b2a2eb
2 changed files with 28 additions and 7 deletions
+24 -6
View File
@@ -20,6 +20,14 @@ export type TaskOptions = {
wait: boolean,
}
interface PatchingError extends Error {
/**
* Interleaved stdout and stderr output on execa errors
* @see https://github.com/sindresorhus/execa#all-1
*/
all?: string
}
const { version } = require('../package.json')
async function main() {
@@ -79,13 +87,23 @@ async function main() {
console.log(
chalk`\n {green.inverse Done! } Patched file: {bold ./${outputName}}\n`,
)
}).catch((error: any) => {
console.error(
chalk`\n {red.inverse.bold Failed! } An error occurred:\n\n`,
error.toString()
)
}).catch((error: PatchingError) => {
const message = (error.all || (error.toString().replace(/^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
.replace(/^I: .+$/gm, line => chalk`{dim ${line}}`)
// De-emphasize (not very helpful) Apktool "could not exec" error message
.replace(
/^.+brut\.common\.BrutException: could not exec.+$/gm,
line => chalk`{dim ${line}}`,
)
if (error.stderr) console.error('\n', error.stderr)
console.error(
chalk`\n {red.inverse.bold Failed! } An error occurred:\n\n${message}`,
)
process.exit(1)
})
+4 -1
View File
@@ -1,5 +1,8 @@
import execa from 'execa'
export function executeJar(path: string, args: string[]) {
return execa('java', ['-jar', path, ...args])
return execa('java', ['-jar', path, ...args], {
// Necessary for showing both stdout and stderr in error output
all: true,
})
}