Skip to content

Commit 242b04d

Browse files
authored
Merge branch 'main' into feature/github-packages-support
2 parents 5668473 + 6fbcd00 commit 242b04d

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎pkg/errors/error.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func formatGitHubValidationError(resp *github.Response, err error) error {
213213
return err
214214
}
215215

216-
parts := make([]string, 0, len(ghErr.Errors)+1)
216+
var parts []string
217217
if summary := sanitizeGitHubValidationText(ghErr.Message); summary != "" {
218218
parts = append(parts, summary)
219219
}

‎pkg/errors/error_test.go‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package errors
33
import (
44
"context"
55
"fmt"
6+
"net/http"
7+
"strings"
8+
"testing"
9+
"time"
10+
611
"github.com/google/go-github/v92/github"
712
"github.com/modelcontextprotocol/go-sdk/mcp"
813
"github.com/stretchr/testify/assert"
914
"github.com/stretchr/testify/require"
10-
"net/http"
11-
"testing"
12-
"time"
1315
)
1416

1517
func TestGitHubErrorContext(t *testing.T) {
@@ -689,6 +691,34 @@ func TestNewGitHubAPIErrorResponse_RateLimits(t *testing.T) {
689691
}
690692

691693
func TestNewGitHubAPIErrorResponse_ValidationMessages(t *testing.T) {
694+
t.Run("large validation error lists are formatted without preallocating from their length", func(t *testing.T) {
695+
const errorCount = 1000
696+
validationErrors := make([]github.Error, errorCount)
697+
for i := range validationErrors {
698+
validationErrors[i] = github.Error{
699+
Resource: "Repository",
700+
Field: fmt.Sprintf("field-%d", i),
701+
Code: "invalid",
702+
}
703+
}
704+
705+
originalErr := &github.ErrorResponse{
706+
Response: &http.Response{StatusCode: http.StatusUnprocessableEntity},
707+
Message: "Validation Failed",
708+
Errors: validationErrors,
709+
}
710+
result := NewGitHubAPIErrorResponse(
711+
ContextWithGitHubErrors(context.Background()),
712+
"API call failed",
713+
nil,
714+
originalErr,
715+
)
716+
717+
text := requireErrorText(t, result)
718+
assert.Equal(t, errorCount+1, len(strings.Split(text, "\n")))
719+
assert.Contains(t, text, "Repository.field-999 (invalid)")
720+
})
721+
692722
t.Run("ruleset ErrorResponse includes sanitized structured validation messages", func(t *testing.T) {
693723
ctx := ContextWithGitHubErrors(context.Background())
694724

0 commit comments

Comments
 (0)