-
Notifications
You must be signed in to change notification settings - Fork 6
chore: lint fixes part 5 #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: pb/coder-lint-fix4
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -405,7 +405,7 @@ func filterBedrockBetaFlags(headers http.Header, model string) { | |
| } | ||
|
|
||
| // writeUpstreamError marshals and writes a given error. | ||
| func (i *interceptionBase) writeUpstreamError(w http.ResponseWriter, antErr *ErrorResponse) { | ||
| func (i *interceptionBase) writeUpstreamError(w http.ResponseWriter, antErr *messagesResponseError) { | ||
| if antErr == nil { | ||
| return | ||
| } | ||
|
|
@@ -415,7 +415,7 @@ func (i *interceptionBase) writeUpstreamError(w http.ResponseWriter, antErr *Err | |
|
|
||
| out, err := json.Marshal(antErr) | ||
| if err != nil { | ||
| i.logger.Warn(context.Background(), "failed to marshal upstream error", slog.Error(err), slog.F("error_payload", slog.F("%+v", antErr))) | ||
| i.logger.Warn(context.Background(), "failed to marshal upstream error", slog.Error(err), slog.F("error_payload", antErr)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. I think the intention of this previous was to |
||
| // Response has to match expected format. | ||
| // See https://docs.claude.com/en/api/errors#error-shapes. | ||
| _, _ = w.Write([]byte(fmt.Sprintf(`{ | ||
|
|
@@ -487,7 +487,7 @@ func accumulateUsage(dest, src any) { | |
| } | ||
| } | ||
|
|
||
| func getErrorResponse(err error) *ErrorResponse { | ||
| func getErrorResponse(err error) *messagesResponseError { | ||
| var apierr *anthropic.Error | ||
| if !errors.As(err, &apierr) { | ||
| return nil | ||
|
|
@@ -505,7 +505,7 @@ func getErrorResponse(err error) *ErrorResponse { | |
| typ = string(detail.Type) | ||
| } | ||
|
|
||
| return &ErrorResponse{ | ||
| return &messagesResponseError{ | ||
| ErrorResponse: &anthropic.ErrorResponse{ | ||
| Error: anthropic.ErrorObjectUnion{ | ||
| Message: msg, | ||
|
|
@@ -517,16 +517,16 @@ func getErrorResponse(err error) *ErrorResponse { | |
| } | ||
| } | ||
|
|
||
| var _ error = &ErrorResponse{} | ||
| var _ error = &messagesResponseError{} | ||
|
|
||
| type ErrorResponse struct { | ||
| type messagesResponseError struct { | ||
| *anthropic.ErrorResponse | ||
|
|
||
| StatusCode int `json:"-"` | ||
| } | ||
|
|
||
| func newErrorResponse(msg error) *ErrorResponse { | ||
| return &ErrorResponse{ | ||
| func newErrorResponse(msg error) *messagesResponseError { | ||
| return &messagesResponseError{ | ||
| ErrorResponse: &shared.ErrorResponse{ | ||
| Error: shared.ErrorObjectUnion{ | ||
| Message: msg.Error(), | ||
|
|
@@ -536,7 +536,7 @@ func newErrorResponse(msg error) *ErrorResponse { | |
| } | ||
| } | ||
|
|
||
| func (a *ErrorResponse) Error() string { | ||
| func (a *messagesResponseError) Error() string { | ||
| if a.ErrorResponse == nil { | ||
| return "" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -157,7 +157,7 @@ newStream: | |||||
| for { | ||||||
| // TODO add outer loop span (https://github.com/coder/aibridge/issues/67) | ||||||
| if err := streamCtx.Err(); err != nil { | ||||||
| lastErr = xerrors.Errorf("stream exit: %w", err) | ||||||
| interceptionErr = xerrors.Errorf("stream exit: %w", err) | ||||||
| break | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -474,8 +474,8 @@ newStream: | |||||
| MsgID: message.ID, | ||||||
| Prompt: prompt, | ||||||
| }) | ||||||
| prompt = "" | ||||||
| promptFound = false | ||||||
| prompt = "" //nolint:ineffassign // reset to prevent double-recording across newStream iterations | ||||||
| promptFound = false //nolint:ineffassign // reset to prevent double-recording across newStream iterations | ||||||
| } | ||||||
|
|
||||||
| if events.IsStreaming() { | ||||||
|
|
@@ -488,7 +488,7 @@ newStream: | |||||
| logger.Warn(ctx, "anthropic stream error", slog.Error(streamErr)) | ||||||
| interceptionErr = antErr | ||||||
| } else { | ||||||
| logger.Warn(ctx, "unknown error", slog.Error(streamErr)) | ||||||
| logger.Warn(ctx, "unknown stream error encountered", slog.Error(streamErr)) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| // Unfortunately, the Anthropic SDK does not support parsing errors received in the stream | ||||||
| // into known types (i.e. [shared.OverloadedError]). | ||||||
| // See https://github.com/anthropics/anthropic-sdk-go/blob/v1.12.0/packages/ssestream/ssestream.go#L172-L174 | ||||||
|
|
@@ -497,14 +497,14 @@ newStream: | |||||
| } | ||||||
| } else if lastErr != nil { | ||||||
| // Otherwise check if any logical errors occurred during processing. | ||||||
| logger.Warn(ctx, "stream failed", slog.Error(lastErr)) | ||||||
| logger.Warn(ctx, "stream processing failed", slog.Error(lastErr)) | ||||||
| interceptionErr = newErrorResponse(xerrors.Errorf("processing error: %w", lastErr)) | ||||||
| } | ||||||
|
|
||||||
| if interceptionErr != nil { | ||||||
| payload, err := i.marshal(interceptionErr) | ||||||
| if err != nil { | ||||||
| logger.Warn(ctx, "failed to marshal error", slog.Error(err), slog.F("error_payload", slog.F("%+v", interceptionErr))) | ||||||
| logger.Warn(ctx, "failed to marshal error", slog.Error(err), slog.F("error_payload", interceptionErr)) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||||||
| } else if err := events.Send(streamCtx, payload); err != nil { | ||||||
| logger.Warn(ctx, "failed to relay error", slog.Error(err), slog.F("payload", payload)) | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.