Skip to content

llms/openai: openai client: return context.Canceled instead of new error declaration#1480

Open
mats852 wants to merge 1 commit intotmc:mainfrom
mats852:fix/openai-client-ctx-cancelled-error
Open

llms/openai: openai client: return context.Canceled instead of new error declaration#1480
mats852 wants to merge 1 commit intotmc:mainfrom
mats852:fix/openai-client-ctx-cancelled-error

Conversation

@mats852
Copy link
Copy Markdown

@mats852 mats852 commented Feb 25, 2026

Returning the standard context.Canceled error from llms/openai/internal/openaiclient/openaiclient.go instead of a new declaration, so callers can evaluate it down the line.

Moreover, since cancelled can be spelled with both 1 and 2 L, it is error prone. Go's standard declaration uses 1 L.

before

completion, err := llms.GenerateFromSinglePrompt(ctx, model, "prompt")

if err != nil && strings.Contains(err.Error(), "cancelled") {
	// handle canceled context
}

after

completion, err := llms.GenerateFromSinglePrompt(ctx, model, "prompt")

if errors.Is(err, context.Canceled) {
	// handle canceled context
}

PR Checklist

  • Read the Contributing documentation.
  • Read the Code of conduct documentation.
  • Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • Describes the source of new concepts.
  • References existing implementations as appropriate.
  • Contains test coverage for new functions.
  • Passes all golangci-lint checks.

@mats852
Copy link
Copy Markdown
Author

mats852 commented Feb 25, 2026

To prevent breaking implementation, we could join errors also, let me know what you think.

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.

1 participant