Skip to content

Commit

Permalink
Fix behavior of pretty print error message when error occurs in contr…
Browse files Browse the repository at this point in the history
…act, add more styles to the error message, issue #15
  • Loading branch information
MarkChenYutian committed Jul 17, 2023
1 parent 3d17ef0 commit 3c6a52e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/vm_core/vm_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,23 @@ function getCallstack(s: C0VM_RT): string[] {
}

function prettyPrintC0Error(e: Error, s: C0VM_RT, print_update: (s: string) => void) {
if (s.state.CurrC0RefLine !== undefined) {
if (s.state.CurrC0RefLine !== undefined && s.state.CurrC0RefLine[0] !== "") {
console.log(s.state.CurrC0RefLine);
print_update(`<span class="stdout-error">
Program aborted at ${s.state.CurrC0RefLine[0]}: Line ${s.state.CurrC0RefLine[1]}
with error message:
${e.message}
Traceback:
${getCallstack(s).join("\n&nbsp;↪")} &larr; Error raised here!</span>`);
${getCallstack(s).join("\n&nbsp;↪&nbsp;")} &larr; <b><i>Error raised here!</i></b></span>`);
} else if (s.state.CurrC0RefLine !== undefined && s.state.CurrC0RefLine[0] === "") {
print_update(`<span class="stdout-error">
Program aborted
with error message:
${e.message}
</span>`);
} else {
print_update(`<span class="stdout-error">
Program aborted
Expand All @@ -243,6 +251,6 @@ function prettyPrintC0Error(e: Error, s: C0VM_RT, print_update: (s: string) => v
${e.message}
Traceback:
${getCallstack(s).join("\n&nbsp;↪")} &larr; Error raised here!</span>`);
${getCallstack(s).join("\n&nbsp;↪")} &larr; <b><i>Error raised here!</i></b></span>`);
}
}

0 comments on commit 3c6a52e

Please sign in to comment.