Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Conversation

@mattjohnsonpint
Copy link
Contributor

@mattjohnsonpint mattjohnsonpint commented May 28, 2025

This continues on the work in #863, implementing for the AssemblyScript SDK.

There are a couple of minor differences:

  • Errors that are thrown via throw new Error(...) will continue to be logged but not emitted via the GraphQL API, because they're likely not intended to be user facing. (In the future we will be able to catch these via try-as.)
  • User-facing error messages can be thrown via utils.throwUserError(...), which logs the error and exits cleanly. The runtime will trap this error message and return it via the GraphQL API errors section.

@trunk-io
Copy link

trunk-io bot commented May 28, 2025

Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information.

Base automatically changed from mjp/hyp-3400-forward-model-invocation-errors to main May 28, 2025 21:24
@mattjohnsonpint mattjohnsonpint force-pushed the mjp/as-error-forwarding branch from a2f42af to 6ffb96a Compare May 28, 2025 21:28
@mattjohnsonpint mattjohnsonpint force-pushed the mjp/as-error-forwarding branch from a98b34b to aacfc68 Compare May 29, 2025 18:02
@mattjohnsonpint mattjohnsonpint marked this pull request as ready for review May 29, 2025 18:04
@mattjohnsonpint mattjohnsonpint requested review from a team and Copilot May 29, 2025 18:04
Copy link
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

This PR adds support for returning user-facing and chat model errors in the AssemblyScript SDK’s GraphQL API response.

  • Hooks a validator into the chat model invocation to parse and throw user errors.
  • Implements validateChatModelResponse and a new ChatModelError type for parsing API error payloads.
  • Adds throwUserError utility and updates Model base class to exit cleanly on user errors.

Reviewed Changes

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

File Description
sdk/assemblyscript/src/models/openai/chat.ts Added validator assignment, validateChatModelResponse, and ChatModelError.
sdk/assemblyscript/src/assembly/utils.ts Introduced resultIsInvalid and throwUserError utilities.
sdk/assemblyscript/src/assembly/models.ts Extended Model with validator hook and user-error exit logic.
CHANGELOG.md Updated changelog entry to include this PR (#864).
Comments suppressed due to low confidence (2)

sdk/assemblyscript/src/models/openai/chat.ts:1593

  • The new validateChatModelResponse function and its branches (empty response, error payload, normal path) lack unit tests. Adding tests will help ensure that future changes don't break these error-handling paths.
function validateChatModelResponse(data: string): ModelError | null {

sdk/assemblyscript/src/assembly/models.ts:102

  • The utils namespace isn't imported in this file, so utils.throwUserError will be undefined. Add or correct the import for the throwUserError function from utils.ts.
utils.throwUserError(`The chat model returned an error: ${err}`);

@mattjohnsonpint mattjohnsonpint merged commit 3d4d592 into main May 29, 2025
40 checks passed
@mattjohnsonpint mattjohnsonpint deleted the mjp/as-error-forwarding branch May 29, 2025 18:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants