Skip to content

[sdk_v2] improves error handling in js sdk #435

Merged
baijumeswani merged 35 commits intomainfrom
prathikrao/improve-js-sdk-errors
Feb 19, 2026
Merged

[sdk_v2] improves error handling in js sdk #435
baijumeswani merged 35 commits intomainfrom
prathikrao/improve-js-sdk-errors

Conversation

@prathikr
Copy link
Copy Markdown
Contributor

@prathikr prathikr commented Feb 11, 2026

JavaScript SDK Improvements

🚀 Error Handling

Error Context Enhancement

  • All streaming errors now include Model ID and Operation Context
  • Original errors are preserved in the cause property for full error chaining
  • Consistent error messages for parse failures, callback errors, and streaming interruptions
  • Fail-fast behavior: Stops processing immediately after the first error to prevent memory bloat

🛠️ Usability & Validation

Strict Input Validation

  • Added validateMessages to ChatClient:
    • Ensures messages array is not empty/null/undefined
    • Validates role and content are non-empty strings
  • Added validateAudioFilePath to AudioClient:
    • Ensures path is a non-empty string
  • Catalog Improvements:
    • getModel and getModelVariant now throw descriptive errors if the item is not found
    • Helpful Hints: Error messages now list available models/variants when a lookup fails (e.g., "Model with alias 'foo' not found. Available models: ...")

✅ Test Coverage

Expanded Validation Tests

  • Added comprehensive null/undefined checks:
    • catalog.getModel(null/undefined)
    • catalog.getModelVariant(null/undefined)
    • client.completeChat(null/undefined)
    • client.completeStreamingChat(null/undefined, callback)
  • Callback Validation:
    • Tests ensuring generic callback functions are valid (not null/undefined/non-function)

📚 Documentation

  • Auto-generated updates:
    • Updated docs/interfaces/*.md to reflect type definition changes in types.ts
    • Ensured documentation stays in sync with code headers

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 11, 2026

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

Project Deployment Actions Updated (UTC)
foundry-local Ready Ready Preview, Comment Feb 19, 2026 5:39am

Request Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk_v2/js/src/catalog.ts
Comment thread sdk_v2/js/src/openai/chatClient.ts
Comment thread sdk_v2/js/src/openai/audioClient.ts
@prathikr prathikr requested a review from Copilot February 19, 2026 00:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk_v2/js/src/catalog.ts
Comment thread sdk_v2/js/src/openai/chatClient.ts Outdated
Comment thread sdk_v2/js/src/openai/chatClient.ts Outdated
Comment thread sdk_v2/js/src/openai/audioClient.ts Outdated
Comment thread sdk_v2/js/src/openai/audioClient.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk_v2/js/src/catalog.ts
Comment thread sdk_v2/js/test/catalog.test.ts Outdated
Comment thread sdk_v2/js/test/openai/chatClient.test.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk_v2/js/src/openai/audioClient.ts
Comment thread sdk_v2/js/test/catalog.test.ts Outdated
Comment thread sdk_v2/js/test/catalog.test.ts Outdated
Comment thread sdk_v2/js/src/catalog.ts
Comment thread sdk_v2/js/src/openai/chatClient.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sdk_v2/js/src/openai/audioClient.ts
Comment thread sdk_v2/js/test/openai/chatClient.test.ts
@prathikr prathikr requested a review from Copilot February 19, 2026 05:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@baijumeswani baijumeswani merged commit fcfea4a into main Feb 19, 2026
15 checks passed
@baijumeswani baijumeswani deleted the prathikrao/improve-js-sdk-errors branch February 19, 2026 07:25
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.

3 participants