Skip to content

Commit 6512b13

Browse files
committed
modelerrors: add NewContextOverflowError constructor
Callers were constructing &ContextOverflowError{Underlying: err} directly. Adding a constructor improves encapsulation and allows future field additions without breaking callers. Update runtime/fallback.go to use the constructor. Assisted-By: docker-agent
1 parent 744db25 commit 6512b13

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

pkg/modelerrors/modelerrors.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ type ContextOverflowError struct {
8484
Underlying error
8585
}
8686

87+
// NewContextOverflowError creates a ContextOverflowError wrapping the given
88+
// underlying error. Use this constructor rather than building the struct
89+
// directly so that future field additions don't break callers.
90+
func NewContextOverflowError(underlying error) *ContextOverflowError {
91+
return &ContextOverflowError{Underlying: underlying}
92+
}
93+
8794
func (e *ContextOverflowError) Error() string {
8895
if e.Underlying == nil {
8996
return "context window overflow"

pkg/runtime/fallback.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func (r *LocalRuntime) tryModelWithFallback(
326326
if lastErr != nil {
327327
wrapped := fmt.Errorf("all models failed: %w", lastErr)
328328
if modelerrors.IsContextOverflowError(lastErr) {
329-
return streamResult{}, nil, &modelerrors.ContextOverflowError{Underlying: wrapped}
329+
return streamResult{}, nil, modelerrors.NewContextOverflowError(wrapped)
330330
}
331331
return streamResult{}, nil, wrapped
332332
}

0 commit comments

Comments
 (0)