Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[BUG] Error handling pattern doesn't match OpenCode plugin conventions (#81) #80

@CasualDeveloper

Description

@CasualDeveloper

Problem

The plugin's error handling doesn't follow the patterns used by OpenCode's official auth plugins (opencode-copilot-auth, opencode-anthropic-auth), causing errors to display incorrectly in the OpenCode UI.

Current behavior

  1. Token refresh failures return a Response object instead of throwing an error:

    return {
      success: false,
      response: new Response(JSON.stringify({ error: "Token refresh failed" }), { status: 401 }),
    };
  2. API error responses are consumed, enriched with custom JSON, and returned as a new Response - this interferes with OpenCode's AI SDK error handling:

Image

Impact

  • Error messages persist incorrectly in the UI
  • Rate limit errors may display as raw JSON instead of user-friendly messages
  • Errors don't integrate with OpenCode's retry logic (isRetryable flag)

Expected behavior

Based on opencode-copilot-auth (lines 88-89):

if (!response.ok) {
  throw new Error(`Token refresh failed: ${response.status}`);
}
  • Token refresh failures should throw errors (OpenCode catches these and displays them properly)
  • API error responses should be returned as-is (OpenCode's AI SDK converts HTTP errors to APICallErrorMessageV2.APIError)
Image

References

  • OpenCode error handling: packages/opencode/src/session/message-v2.ts:fromError()
  • Official plugin pattern: opencode-copilot-auth/index.mjs:88-89

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions