Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func formatGitHubValidationError(resp *github.Response, err error) error {
return err
}

parts := make([]string, 0, len(ghErr.Errors)+1)
var parts []string
if summary := sanitizeGitHubValidationText(ghErr.Message); summary != "" {
parts = append(parts, summary)
}
Expand Down
36 changes: 33 additions & 3 deletions pkg/errors/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package errors
import (
"context"
"fmt"
"net/http"
"strings"
"testing"
"time"

"github.com/google/go-github/v92/github"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"net/http"
"testing"
"time"
)

func TestGitHubErrorContext(t *testing.T) {
Expand Down Expand Up @@ -689,6 +691,34 @@ func TestNewGitHubAPIErrorResponse_RateLimits(t *testing.T) {
}

func TestNewGitHubAPIErrorResponse_ValidationMessages(t *testing.T) {
t.Run("large validation error lists are formatted without preallocating from their length", func(t *testing.T) {
const errorCount = 1000
validationErrors := make([]github.Error, errorCount)
for i := range validationErrors {
validationErrors[i] = github.Error{
Resource: "Repository",
Field: fmt.Sprintf("field-%d", i),
Code: "invalid",
}
}

originalErr := &github.ErrorResponse{
Response: &http.Response{StatusCode: http.StatusUnprocessableEntity},
Message: "Validation Failed",
Errors: validationErrors,
}
result := NewGitHubAPIErrorResponse(
ContextWithGitHubErrors(context.Background()),
"API call failed",
nil,
originalErr,
)

text := requireErrorText(t, result)
assert.Equal(t, errorCount+1, len(strings.Split(text, "\n")))
assert.Contains(t, text, "Repository.field-999 (invalid)")
})

t.Run("ruleset ErrorResponse includes sanitized structured validation messages", func(t *testing.T) {
ctx := ContextWithGitHubErrors(context.Background())

Expand Down
Loading