Skip to content

fix: updateDocument returns an error instead of throwing when no handler matches the document kind - #1544

Open
shoemoney wants to merge 1 commit into
vercel:mainfrom
shoemoney:fix/update-document-missing-handler
Open

shoemoney wants to merge 1 commit into
vercel:mainfrom
shoemoney:fix/update-document-missing-handler

Conversation

@shoemoney

Copy link
Copy Markdown

When updateDocument finds 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 tools editDocument and requestSuggestions do the same.

This path is reachable with real data: the image handler was removed from documentHandlersByArtifactKind in #1145, but the DB schema still allows kind image, so asking the model to rewrite a legacy image document hits the throw.

Changes:

  • Return { error: "This document type (image) can no longer be rewritten." } instead of throwing, matching the existing not-found and forbidden returns.
  • Move the handler lookup ahead of the data-clear stream event so the artifact panel is not wiped when the update cannot proceed.

Verified by exercising the tool's execute with a mocked kind image document: before it throws No document handler found for kind: image, after it resolves the error object. biome check and tsc --noEmit pass. No unit test seam exists in the repo (Playwright e2e only), so verification was a standalone harness.

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.
@vercel

vercel Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

@shoemoney is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@shoemoney

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant