Skip to content

Commit 4fb0d4c

Browse files
* Error logging for exceptions during build cleanup
* Compacted log message filter regexes * Moved pre-build command after initialization of the output folder in case this command somehow wants to operate on it somehow * Better error message handling when post-build command fails * Forwarding post-build command error
1 parent c51f566 commit 4fb0d4c

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/arduino/arduino.ts

+24-22
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ export class ArduinoApp {
182182
})
183183
.catch((reason) => {
184184
this._building = false;
185-
// TODO EW, 2020-02-19: Report unhandled error (Logger?)
185+
logger.notifyUserError("ArduinoApp.build",
186+
reason,
187+
`Unhandled exception when cleaning up build (${mode}).`);
186188
return false;
187189
});
188190
}
@@ -457,7 +459,7 @@ Please make sure the folder is not occupied by other procedures .`);
457459

458460
if (!this.boardManager.currentBoard) {
459461
if (mode !== BuildMode.Analyze) {
460-
logger.notifyUserError("getBoardBuildString", new Error(constants.messages.NO_BOARD_SELECTED));
462+
logger.notifyUserError("boardManager.currentBoard", new Error(constants.messages.NO_BOARD_SELECTED));
461463
}
462464
return false;
463465
}
@@ -530,13 +532,6 @@ Please make sure the folder is not occupied by other procedures .`);
530532
arduinoChannel.show();
531533
arduinoChannel.start(`${mode} sketch '${dc.sketch}'`);
532534

533-
// TODO EW: What should we do with pre-/post build commands when running
534-
// analysis? Some could use it to generate/manipulate code which could
535-
// be a prerequisite for a successful build
536-
if (!await this.runPrePostBuildCommand(dc, "pre")) {
537-
return false;
538-
}
539-
540535
if (buildDir || dc.output) {
541536
const outputPath = path.resolve(ArduinoWorkspace.rootPath, buildDir || dc.output);
542537
const dirPath = path.dirname(outputPath);
@@ -551,6 +546,13 @@ Please make sure the folder is not occupied by other procedures .`);
551546
arduinoChannel.warning(msg);
552547
}
553548

549+
// TODO EW: What should we do with pre-/post build commands when running
550+
// analysis? Some could use it to generate/manipulate code which could
551+
// be a prerequisite for a successful build
552+
if (!await this.runPrePostBuildCommand(dc, "pre")) {
553+
return false;
554+
}
555+
554556
// stop serial monitor when everything is prepared and good
555557
// what makes restoring of its previous state easier
556558
if (mode === BuildMode.Upload || mode === BuildMode.UploadProgrammer) {
@@ -562,8 +564,9 @@ Please make sure the folder is not occupied by other procedures .`);
562564
args.push(path.join(ArduinoWorkspace.rootPath, dc.sketch));
563565

564566
const cleanup = async (result: "ok" | "error") => {
567+
let ret = true;
565568
if (result === "ok") {
566-
await this.runPrePostBuildCommand(dc, "post");
569+
ret = await this.runPrePostBuildCommand(dc, "post");
567570
}
568571
await cocopa.conclude();
569572
if (mode === BuildMode.Upload || mode === BuildMode.UploadProgrammer) {
@@ -572,6 +575,7 @@ Please make sure the folder is not occupied by other procedures .`);
572575
await SerialMonitor.getInstance().openSerialMonitor();
573576
}
574577
}
578+
return ret;
575579
}
576580
const stdoutcb = (line: string) => {
577581
if (cocopa.callback) {
@@ -591,17 +595,13 @@ Please make sure the folder is not occupied by other procedures .`);
591595
line = `${line}${os.EOL}`;
592596
}
593597
if (!verbose) {
594-
// Don't spill log with spurious info from the backend
595-
// This list could be fetched from a config file to
596-
// accommodate messages of unknown board packages, newer
597-
// backend revisions etc.
598+
// Don't spill log with spurious info from the backend. This
599+
// list could be fetched from a config file to accommodate
600+
// messages of unknown board packages, newer backend revisions
598601
const filters = [
599602
/^Picked\sup\sJAVA_TOOL_OPTIONS:\s+/,
600-
/^\d+\d+-\d+-\d+T\d+:\d+:\d+.\d+Z\sINFO\s/,
601-
/^\d+\d+-\d+-\d+T\d+:\d+:\d+.\d+Z\sWARN\s/,
602-
/^DEBUG\s+/,
603-
/^TRACE\s+/,
604-
/^INFO\s+/,
603+
/^\d+\d+-\d+-\d+T\d+:\d+:\d+.\d+Z\s(?:INFO|WARN)\s/,
604+
/^(?:DEBUG|TRACE|INFO)\s+/,
605605
];
606606
for (const f of filters) {
607607
if (line.match(f)) {
@@ -618,9 +618,11 @@ Please make sure the folder is not occupied by other procedures .`);
618618
undefined,
619619
{ stdout: stdoutcb, stderr: stderrcb },
620620
).then(async () => {
621-
await cleanup("ok");
622-
arduinoChannel.end(`${mode} sketch '${dc.sketch}'${os.EOL}`);
623-
return true;
621+
const ret = await cleanup("ok");
622+
if (ret) {
623+
arduinoChannel.end(`${mode} sketch '${dc.sketch}'${os.EOL}`);
624+
}
625+
return ret;
624626
}, async (reason) => {
625627
await cleanup("error");
626628
const msg = reason.code

0 commit comments

Comments
 (0)