abi-gen: exit when black fails to parse Python

Note: this is not the same case as when the black executable can't be
found; that case is still just a (non-fatal) warning.
This commit is contained in:
F. Eugene Aumson 2020-01-14 18:38:43 -05:00 committed by Jacob Evans
parent 79b6c3c1af
commit 277fb92f9e
No known key found for this signature in database
GPG Key ID: 2036DA2ADDFB0842

View File

@ -277,10 +277,16 @@ for (const abiFileName of abiFileNames) {
// use command-line tool black to reformat, if its available
try {
execSync(`black --line-length 79 ${outFilePath}`);
} catch {
logUtils.warn(
'Failed to reformat generated Python with black. Do you have it installed? Proceeding anyways...',
);
} catch (e) {
const BLACK_RC_CANNOT_PARSE = 123; // empirical black exit code
if (e.status === BLACK_RC_CANNOT_PARSE) {
logUtils.warn(
'Failed to reformat generated Python with black. Exception thrown by execSync("black ...") follows.',
);
throw e;
} else {
logUtils.warn('Failed to invoke black. Do you have it installed? Proceeding anyways...');
}
}
}