fix: helpful error when external returns a non-cloneable value - #149
Merged
KnorpelSenf merged 2 commits intoMay 16, 2026
Merged
Conversation
Member
|
@Dramex I have fixed CI upstream, please update your branch |
Member
|
Also: I have seen all of your other amazing contributions, and I am sorry for ghosting your for so long. This is probably the first time since the inception of grammY that I am this unresponsive for this long, there is just too much going on in my life right now (only good things). I am very much looking forward to merging them soon, thanks for your patience! I am still present in https://t.me/grammyjs if you ever want to have a chat about anything |
`external` runs the caller's task outside the deterministic replay and then clones the result via `structuredClone` so the returned value is immutable across replays. When the task returns something that `structuredClone` cannot handle (e.g. a function), the clone throws a `DataCloneError` whose message does not mention `external`, the conversation, or the fix. Wrap the `structuredClone` call so that such failures raise a new `Error` that points at `external`, suggests `beforeStore`/`afterLoad` for custom serialisation, and keeps the original `DataCloneError` as its `cause` for debugging. Closes grammyjs#140.
Dramex
force-pushed
the
fix/external-structured-clone-error
branch
from
May 15, 2026 15:09
72fd7c9 to
deee00a
Compare
Contributor
Author
|
rebased onto main. and no worries, life first. |
KnorpelSenf
reviewed
May 16, 2026
Member
|
TYSM! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #140.
conversation.external(...)clones its result withstructuredCloneso the value is immutable across replays. When the task returns a non-cloneable value (for example, a function), the nativeDataCloneErrorthat falls out doesn't mentionexternal, the conversation, or what to do about it — the reporter on #140 hit exactly this.Wrap the
structuredClone(ret)call insrc/conversation.tsso that failures throw a newErrorthat:externalas the site where cloning is required.beforeStore/afterLoadfor custom serialization (already documented in the JSDoc above).DataCloneErroron.causefor debugging.Changes
src/conversation.ts: try/catch aroundstructuredClone(ret), rethrow with a helpful message andcause.test/conversation.test.ts: new case exercisingconversation.external(() => () => 0)and asserting the new message andcause.Test plan
deno task test --no-check— 11 suites / 117 steps pass (the repo has pre-existingRequestInit.bodytype errors intest/conversation.test.ts:390,525that reproduce onmainwithout this change).deno fmt --checkdeno lint