JSON.parse errors handling in dotnetbuilderwrapper

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 2ea85c2f67
commit c592891dde
  1. 32
      BuildServer/lib/tasks/dotnetbuilderwrapper.js

@ -16,12 +16,24 @@ const wrapBuilder = (builder, input, onExit) => {
errorBuffer.write(data);
});
builder.on("exit", (code) => onExit(code, resultBuffer.getContentsAsString(), errorBuffer.getContentsAsString()));
builder.on("exit", (code) => {
resultBuffer.end();
errorBuffer.end();
onExit(code, resultBuffer.getContentsAsString(), errorBuffer.getContentsAsString());
});
builder.stdin.write(input);
builder.stdin.end();
};
const safeParseJson = (data) => {
try {
return { "parsed": JSON.parse(data) };
} catch (err) {
return { err };
}
};
module.exports = (params, processor) => ({
"process": () => {
const input = JSON.stringify(params);
@ -29,15 +41,23 @@ module.exports = (params, processor) => ({
processor.onInfo(`DotNetBuilderWrapper processing (at ${new Date().toISOString()}): ${input}`);
wrapBuilder(builder, input, (code, result, error) => {
if (code) {
processor.onError(`Return code is ${code}\r\n${error}`);
wrapBuilder(builder, input, (code, result, builderError) => {
if (code || builderError) {
processor.onError(`Return code is ${code}\r\n${builderError}`);
return processor.done();
}
const { parsed, err } = safeParseJson(result);
if (err || !parsed || !parsed.Messages) {
processor.onError(`Malformed JSON: ${err}`);
processor.onInfo(result);
return processor.done();
}
const report = JSON.parse(result);
const messages = report.Messages;
const messages = parsed.Messages;
messages.forEach((message) => {
if (!message) {

Loading…
Cancel
Save