MCPcopy Index your code
hub / github.com/docker/docker-agent / TestFormatError

Function TestFormatError

pkg/modelerrors/modelerrors_test.go:507–558  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

505}
506
507func TestFormatError(t *testing.T) {
508 t.Parallel()
509
510 t.Run("nil error", func(t *testing.T) {
511 t.Parallel()
512 assert.Empty(t, FormatError(nil))
513 })
514
515 t.Run("stream truncation shows prefill/timeout guidance", func(t *testing.T) {
516 t.Parallel()
517 err := fmt.Errorf("error receiving from stream: %w", errors.New("unexpected end of JSON input"))
518 msg := FormatError(err)
519 assert.Contains(t, msg, "closed unexpectedly before it completed its response")
520 // Covers both the silent-prefill drop and a mid-stream cut, since the
521 // truncation patterns can fire after partial tokens have streamed too.
522 assert.Contains(t, msg, "prefill")
523 assert.Contains(t, msg, "mid-stream")
524 assert.NotContains(t, msg, "unexpected end of JSON input")
525 })
526
527 t.Run("context overflow shows user-friendly message", func(t *testing.T) {
528 t.Parallel()
529 err := NewContextOverflowError(errors.New("prompt is too long"))
530 msg := FormatError(err)
531 assert.Contains(t, msg, "context window")
532 assert.Contains(t, msg, "/compact")
533 assert.NotContains(t, msg, "prompt is too long")
534 })
535
536 t.Run("wrapped context overflow shows user-friendly message", func(t *testing.T) {
537 t.Parallel()
538 err := fmt.Errorf("outer: %w", NewContextOverflowError(errors.New("prompt is too long")))
539 msg := FormatError(err)
540 assert.Contains(t, msg, "context window")
541 assert.Contains(t, msg, "/compact")
542 })
543
544 t.Run("generic error preserves message", func(t *testing.T) {
545 t.Parallel()
546 err := errors.New("authentication failed")
547 assert.Equal(t, "authentication failed", FormatError(err))
548 })
549
550 t.Run("context overflow takes precedence over status formatting", func(t *testing.T) {
551 t.Parallel()
552 underlying := errors.New("prompt is too long: 226360 tokens > 200000 maximum")
553 wrapped := NewContextOverflowError(&StatusError{StatusCode: 400, Err: underlying})
554 msg := FormatError(wrapped)
555 assert.Contains(t, msg, "context window")
556 assert.Contains(t, msg, "/compact")
557 })
558}
559
560func TestStatusErrorParsesProviderBody(t *testing.T) {
561 t.Parallel()

Callers

nothing calls this directly

Calls 4

FormatErrorFunction · 0.85
NewContextOverflowErrorFunction · 0.85
RunMethod · 0.65
NewMethod · 0.45

Tested by

no test coverage detected