rudimentary error reporting

This commit is contained in:
りき萌 2024-08-19 23:56:11 +02:00
parent 6eab20bb25
commit 1c0fa7197c
5 changed files with 90 additions and 10 deletions

View file

@ -2,9 +2,9 @@ const defaultBrush = `
; This is your brush.
; Feel free to edit it to your liking!
(stroke
8 ; thickness
(rgba 0.0 0.0 0.0 1.0) ; color
(vec)) ; position
8 ; thickness
(rgba 0.0 0.0 0.0 1.0) ; color
(vec)) ; position
`.trim();
export class BrushEditor extends HTMLElement {
@ -28,11 +28,51 @@ export class BrushEditor extends HTMLElement {
}),
);
});
this.errorHeader = this.appendChild(document.createElement("h1"));
this.errorHeader.classList.add("error-header");
this.errorArea = this.appendChild(document.createElement("pre"));
this.errorArea.classList.add("errors");
}
get code() {
return this.textArea.textContent;
}
resetErrors() {
this.errorHeader.textContent = "";
this.errorArea.textContent = "";
}
renderHakuResult(phase, result) {
this.resetErrors();
console.log(result);
if (result.status != "error") return;
this.errorHeader.textContent = `${phase} failed`;
if (result.errorKind == "diagnostics") {
// This is kind of wooden; I'd prefer if the error spans were rendered inline in text,
// but I haven't integrated anything for syntax highlighting yet that would let me
// do that.
this.errorArea.textContent = result.diagnostics
.map(
(diagnostic) => `${diagnostic.start}..${diagnostic.end}: ${diagnostic.message}`,
)
.join("\n");
} else if (result.errorKind == "plain") {
this.errorHeader.textContent = result.message;
} else if (result.errorKind == "exception") {
// TODO: This should show a stack trace.
this.errorArea.textContent = `an exception occurred: ${result.message}`;
} else {
console.warn(`unknown error kind: ${result.errorKind}`);
this.errorHeader.textContent = "(unknown error kind)";
}
}
}
customElements.define("rkgk-brush-editor", BrushEditor);