Skip to content

Keep exception messages through pickle and copy - #376

Open
anbuzin wants to merge 2 commits into
mainfrom
fix-error-message-pickle
Open

anbuzin wants to merge 2 commits into
mainfrom
fix-error-message-pickle

Conversation

@anbuzin

@anbuzin anbuzin commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Pickling or copying an UnsupportedProviderError or DownloadError could mangle its message by treating the formatted text as the provider ID or URL. We now rebuild each error with the original ID or URL, and the message stays the same.

import pickle

try:
    ai.get_provider("amazon-bedrock")
except ai.UnsupportedProviderError as exc:
    restored = pickle.loads(pickle.dumps(exc))
    print(str(restored) == str(exc))  # before: False; after: True

UnsupportedProviderError and DownloadError take an identifier or URL in
their constructors, but store formatted text in Exception.args. The
default pickle and copy paths pass that text back into the constructors
and format it again.

Restore each error from its original constructor argument and instance
state. Keep the download error's formatted args so status text survives.
Continue to omit causes, so an unpicklable cause does not prevent a
copy.

Cover pickle and deep copy, including status details and an unpicklable
cause.
@anbuzin anbuzin added the fix Bug fix label Nov 20, 2026
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-python Ready Ready Preview, v0 Nov 20, 2026 12:09am UTC

This branch was successfully deployed

1 active deployment
Preview — 06ea5de3 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant