fix: updateDocument returns an error instead of throwing when no handler matches the document kind - #1544
Open
shoemoney wants to merge 1 commit into
Open
fix: updateDocument returns an error instead of throwing when no handler matches the document kind#1544shoemoney wants to merge 1 commit into
shoemoney wants to merge 1 commit into
Conversation
updateDocument throws when a document's kind has no registered handler, which crashes the tool call instead of giving the model a result it can relay. Documents of kind 'image' still exist in the database (the schema allows it) but the image handler was removed in vercel#1145, so rewriting a legacy image document hits this path. Return an error object instead, matching the tool's own convention for 'Document not found' and 'Forbidden'. The handler lookup now happens before the data-clear event so the artifact panel is not wiped when the update cannot proceed.
Contributor
|
@shoemoney is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
CI note: Vercel – chatbot failure is pre-existing on main/trunk and unrelated to this PR's changed files. Fork head 195a435 shows only this Vercel failure and 10/10 sampled fork PRs have the same FAILURE while main c2f8235 shows Vercel success plus build/test success; this PR only touches lib/ai/tools/update-document.ts unrelated to deployment. No code fix required from this PR; rebase/label will clear it. |
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.
When
updateDocumentfinds no handler for a document's kind, it throws, which crashes the tool call instead of giving the model a result it can relay to the user. The function's own convention ten lines up is to return an error object (Document not found,Forbidden), and the sibling toolseditDocumentandrequestSuggestionsdo the same.This path is reachable with real data: the image handler was removed from
documentHandlersByArtifactKindin #1145, but the DB schema still allows kindimage, so asking the model to rewrite a legacy image document hits the throw.Changes:
{ error: "This document type (image) can no longer be rewritten." }instead of throwing, matching the existing not-found and forbidden returns.data-clearstream event so the artifact panel is not wiped when the update cannot proceed.Verified by exercising the tool's
executewith a mocked kindimagedocument: before it throwsNo document handler found for kind: image, after it resolves the error object.biome checkandtsc --noEmitpass. No unit test seam exists in the repo (Playwright e2e only), so verification was a standalone harness.