Skip to content

fix(ai): throw InvalidResponseDataError when audio format cannot be d…#15815

Open
Abuhaithem wants to merge 1 commit into
vercel:mainfrom
Abuhaithem:fix/audio-file-sdk-error
Open

fix(ai): throw InvalidResponseDataError when audio format cannot be d…#15815
Abuhaithem wants to merge 1 commit into
vercel:mainfrom
Abuhaithem:fix/audio-file-sdk-error

Conversation

@Abuhaithem
Copy link
Copy Markdown

DefaultGeneratedAudioFile (packages/ai/src/generate-speech/generated-audio-file.ts) threw a plain JavaScript Error when it could not derive an audio format from the provider's media type — it even carried a // TODO this should be an AI SDK error comment.

Because the error did not extend AISDKError, callers could not distinguish it from an unexpected runtime error via AISDKError.isInstance(...), and it was inconsistent with the rest of the SDK's error handling. The path is reachable when a provider returns audio with a malformed media type (e.g. audio/ — an empty subtype), which leaves the derived format empty.

Summary

  • Replace the generic Error with InvalidResponseDataError from @ai-sdk/provider, passing the offending media type as data and a clearer message.
  • Remove the stale // TODO this should be an AI SDK error comment.
  • Add generated-audio-file.test.ts covering format derivation and the new error behavior.

Manual Verification

pnpm --filter ai exec vitest --config vitest.node.config.js --run src/generate-speech/generated-audio-file.test.ts   # 5 passed
pnpm --filter ai exec vitest --config vitest.edge.config.js --run src/generate-speech/generated-audio-file.test.ts   # 5 passed
pnpm --filter ai exec vitest --config vitest.node.config.js --run src/generate-speech/generate-speech.test.ts        # 8 passed (no regressions)

Additional checks:

  • npx ultracite check <changed files> — clean (formatting + lint).
  • npx tsc --build packages/ai — exit 0.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features) — n/a, internal-only change
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #15814

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.

DefaultGeneratedAudioFile throws a generic Error instead of AISDKError when audio format cannot be determined

1 participant