Skip to content

Add error handling for message conversion in sendChatHistoryMessagesAsync#163

Merged
pontemonti merged 3 commits intousers/johanb/RTP_OpenAIfrom
copilot/sub-pr-157
Jan 27, 2026
Merged

Add error handling for message conversion in sendChatHistoryMessagesAsync#163
pontemonti merged 3 commits intousers/johanb/RTP_OpenAIfrom
copilot/sub-pr-157

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 27, 2026

Adds try-catch around convertToChatHistoryMessages() in sendChatHistoryMessagesAsync(), matching the error handling pattern used for session.getItems() in sendChatHistoryAsync().

Changes:

  • Wrap convertToChatHistoryMessages() call in try-catch block that returns failed OperationResult on error
  • Use defensive error coercion: err instanceof Error ? err : new Error(String(err))
  • Add test cases for both Error and non-Error thrown values (EH-05, EH-06)

Before:

const chatHistoryMessages = this.convertToChatHistoryMessages(messages);
// Unhandled errors propagate as exceptions

After:

let chatHistoryMessages: ChatHistoryMessage[];
try {
  chatHistoryMessages = this.convertToChatHistoryMessages(messages);
} catch (err: unknown) {
  const error = err instanceof Error ? err : new Error(String(err));
  return OperationResult.failed(new OperationError(error));
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 27, 2026 19:53
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
…lank line

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on error handling and tests for chat history API Add error handling for message conversion in sendChatHistoryMessagesAsync Jan 27, 2026
Copilot AI requested a review from pontemonti January 27, 2026 20:01
@pontemonti pontemonti marked this pull request as ready for review January 27, 2026 21:48
@pontemonti pontemonti requested a review from a team as a code owner January 27, 2026 21:48
@pontemonti pontemonti merged commit 83d15b3 into users/johanb/RTP_OpenAI Jan 27, 2026
1 check passed
@pontemonti pontemonti deleted the copilot/sub-pr-157 branch January 27, 2026 21:48
pontemonti added a commit that referenced this pull request Jan 28, 2026
* Add chat history API for OpenAI

* fix: update uuid and @types/uuid dependencies to use catalog

* fix: correct header formatting in PRD for OpenAI sendChatHistoryAsync API

* refactor: remove unnecessary logging and improve message role validation in McpToolRegistrationService

* refactor: simplify role extraction in McpToolRegistrationService and remove validation

* Add @types/uuid and uuid dependencies

* Remove early return for empty messages in sendChatHistoryMessagesAsync (#158)

* Initial plan

* fix: ensure MCP call is made even when messages array is empty

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

* Remove fragile error handling from sendChatHistory methods (#159)

* Initial plan

* Remove fragile 'is required' check from sendChatHistory methods

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

* Update tests/tooling-extensions-openai/sendChatHistoryAsync.test.ts

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix error handling in sendChatHistoryAsync and empty array test expectations (#160)

* Initial plan

* Fix test failures: wrap session.getItems() in try-catch and update test expectations for empty arrays

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
Co-authored-by: Johan Broberg <johan@pontemonti.net>

* Add error handling for message conversion in sendChatHistoryMessagesAsync (#163)

* Initial plan

* Add error handling for convertToChatHistoryMessages and test

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

* Address code review feedback: safer error handling and remove extra blank line

Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>

---------

Co-authored-by: Johan Broberg <johanb@microsoft.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: pontemonti <7850950+pontemonti@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

2 participants