mirror of
https://github.com/coder/coder.git
synced 2026-06-04 21:48:22 +00:00
4751416b29
**Breaking change for changelog:**
> `codersdk.Chat.last_error` now returns a structured `ChatError` object
(`{message, kind, provider, retryable, status_code, detail}`) instead of
a plain string. The chats API is experimental
(`/api/experimental/chats`), so this ships without a deprecation cycle;
consumers reading `chat.last_error` as a string must update to read
`chat.last_error.message`. SDK/generated TypeScript terminal error
payloads now use the single `ChatError` type; the live stream error
payload type is renamed from `ChatStreamError` to `ChatError`.
Persisted chat errors now carry the same provider-specific detail (kind,
provider, retryable, HTTP status, optional detail) as the live stream,
so refreshing a failed chat rehydrates with the full structured error
instead of a one-line headline.
Existing rows are migrated in place: legacy text errors are wrapped into
`{message, kind: "generic"}` so already-errored chats still render, and
rows with `last_error IS NULL` stay NULL. Internally, persisted fallback
decoding now reuses the existing `chaterror.KindGeneric` constant, with
no JSON value change.
Closes CODAGT-239
41 lines
888 B
Go
41 lines
888 B
Go
package chaterror
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func TerminalErrorPayload(classified ClassifiedError) *codersdk.ChatError {
|
|
if classified.Message == "" {
|
|
return nil
|
|
}
|
|
return &codersdk.ChatError{
|
|
Message: classified.Message,
|
|
Detail: classified.Detail,
|
|
Kind: classified.Kind,
|
|
Provider: classified.Provider,
|
|
Retryable: classified.Retryable,
|
|
StatusCode: classified.StatusCode,
|
|
}
|
|
}
|
|
|
|
func StreamRetryPayload(
|
|
attempt int,
|
|
delay time.Duration,
|
|
classified ClassifiedError,
|
|
) *codersdk.ChatStreamRetry {
|
|
if classified.Message == "" {
|
|
return nil
|
|
}
|
|
return &codersdk.ChatStreamRetry{
|
|
Attempt: attempt,
|
|
DelayMs: delay.Milliseconds(),
|
|
Error: retryMessage(classified),
|
|
Kind: classified.Kind,
|
|
Provider: classified.Provider,
|
|
StatusCode: classified.StatusCode,
|
|
RetryingAt: time.Now().Add(delay),
|
|
}
|
|
}
|