Skip to content

Commit

Permalink
fix: dealing with edge case where error cannot be serialised
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Nov 7, 2024
1 parent 0ddd329 commit d779d8b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/RPCServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ function composeMessage(error: unknown): string {
if (typeof error === 'object' && error?.constructor?.name != null) {
return `Non-error object ${error.constructor.name} was thrown`;
}
return `Non-error value ${error} was thrown`;
// If an object is not serialisable (for example, Object.create(null)), then
// an error would be raised when trying to convert it to a string. In that
// case, simply avoid serialising the error.
try {
return `Non-error value ${error} was thrown`;
} catch (e) {
return 'Non-error value was thrown'
}
}

/**
Expand Down

0 comments on commit d779d8b

Please sign in to comment.