Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

fix: compile error doesn't show #204

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/app/modules/core/dialogs/upload/upload.dialog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {TranslateService} from "@ngx-translate/core";
import ArduinoUploader from "../../../../services/arduino-uploader/ArduinoUploader";
import {DialogState} from "../../../../state/dialog.state";
import {RobotWiredState} from "../../../../state/robot.wired.state";
Expand Down Expand Up @@ -43,6 +42,13 @@ export class UploadDialog {
source_code, board, libraries
})
})
if (!res.ok) {
let message: string = await res.text()
try {
message = JSON.parse(message).detail
} catch {}
throw new Error(message)
}

return await res.json() as Record<string, string>
}
Expand Down Expand Up @@ -82,15 +88,11 @@ export class UploadDialog {
this.uploadState.setStatusMessage('COMPILATION_STARTED');
const response = await this.compile(source_code, board, libraries).catch(error => {
this.uploadState.setStatusMessage('COMPILATION_FAILED');
if (!error.toString().startsWith("Error: Request failed: 500 ")) {
console.error(error);
return;
}
// make the printed red text
console.log('%c' + error.toString().replace("Error: Request failed: 500 ", ""), 'color: red');
console.log('%c' + error.toString(), 'color: red');

// remove the last 4 lines of the error message
const errorLines = error.toString().replace("Error: Request failed: 500 ", "").split("\n");
const errorLines = error.toString().split("\n");
errorLines.splice(errorLines.length - 5, 5);
const errorString = errorLines.join("\n");
this.uploadState.setError(errorString)
Expand Down
Loading