Skip to content

Commit

Permalink
catch result serialization errors and return as cell error
Browse files Browse the repository at this point in the history
fixes #51
  • Loading branch information
jaked committed Aug 2, 2024
1 parent 153bbc0 commit c99ddf2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/server/src/executeCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function isHTMLElementLike(obj: unknown): obj is PossibleHTML {
// I don't really understand how async stack traces work
// but I've seen all of these as the top internal stack frame
// before the cell code
const stackFrameRegex = /^\s+at (Domain|Runner|executeCell)/;
const stackFrameRegex = /^\s+at (Domain|Runner|executeCell|mimeTaggedResultOf)/;

function rewriteStack(stack: undefined | string): undefined | string {
if (!stack) {
Expand Down Expand Up @@ -82,7 +82,11 @@ function mimeTaggedResultOf(result: any) {
) {
return result;
} else if (typeof result === "object") {
return { mime: "application/json", data: JSON.stringify(result) };
try {
return { mime: "application/json", data: JSON.stringify(result) };
} catch (e) {
return mimeTaggedResultOf(e);
}
} else {
return { mime: "text/x-javascript", data: JSON.stringify(result) };
}
Expand Down

0 comments on commit c99ddf2

Please sign in to comment.