github/github-mcp-server · error
failed to convert string %s to int64: %w
Error message
failed to convert string %s to int64: %w
What it means
Returned by convertStringToBigInt when strconv.ParseInt fails on a base-10 64-bit parse of a string. It is the leaf conversion error wrapped by the slice converters (267, 270). The %w-embedded error is strconv's *NumError, whose Reason field is ErrSyntax for malformed strings or ErrRange for overflow.
Source
Thrown at pkg/github/params.go:306
}
}
func convertStringSliceToBigIntSlice(s []string) ([]int64, error) {
int64Slice := make([]int64, len(s))
for i, str := range s {
val, err := convertStringToBigInt(str, 0)
if err != nil {
return nil, fmt.Errorf("failed to convert element %d (%s) to int64: %w", i, str, err)
}
int64Slice[i] = val
}
return int64Slice, nil
}
func convertStringToBigInt(s string, def int64) (int64, error) {
v, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return def, fmt.Errorf("failed to convert string %s to int64: %w", s, err)
}
return v, nil
}
// OptionalBigIntArrayParam is a helper function that can be used to fetch a requested parameter from the request.
// It does the following checks:
// 1. Checks if the parameter is present in the request, if not, it returns an empty slice
// 2. If it is present, iterates the elements, checks each is a string, and converts them to int64 values
func OptionalBigIntArrayParam(args map[string]any, p string) ([]int64, error) {
// Check if the parameter is present in the request
if _, ok := args[p]; !ok {
return []int64{}, nil
}
switch v := args[p].(type) {
case nil:
return []int64{}, nil
case []string:View on GitHub (pinned to 0ea1f775a7)
Solutions
- Validate strings with strconv.ParseInt(s, 10, 64) client-side before sending
- Strip formatting characters (commas, spaces, 'n' suffixes, quotes) at the boundary where external data enters
- For >64-bit values confirm the target parameter truly takes int64; if it takes a GitHub GraphQL node ID, send the base64 string in the *_id string parameter instead
Example fix
// before
{"repository_id":"123n"}
// after
{"repository_id":"123"} Defensive patterns
Strategy: validation
Validate before calling
func parseBigInt(s string) (int64, error) {
s = strings.TrimSpace(s)
s = strings.ReplaceAll(s, ",", "")
n, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, fmt.Errorf("%q is not a base-10 int64: %w", s, err)
}
return n, nil
} Type guard
func isParsableInt64(s string) bool {
_, err := strconv.ParseInt(strings.TrimSpace(s), 10, 64)
return err == nil
} Try / catch
n, err := convertStringToBigInt(idStr, 0)
if err != nil {
var ne *strconv.NumError
if errors.As(err, &ne) && ne.Err == strconv.ErrRange {
// out of int64 range: wrong kind of ID — route to the string-ID parameter
}
// ErrSyntax: clean the string and retry once
} Prevention
- Standardize on trimmed, unformatted base-10 strings for numeric IDs
- Distinguish ErrSyntax vs ErrRange when handling strconv errors — they need different fixes
- Watch for 'n' suffixes from BigInt serialization when integrating JS clients
When it happens
Trigger: ParseInt on "", "abc", "12.0", "+ 1", or hex/exponent forms → ErrSyntax; parsing "99999999999999999999" (> int64 max 9223372036854775807) → ErrRange; strings containing U+FFFD or non-ASCII digits.
Common situations: IDs scraped from HTML/UI text carrying formatting; locale digit groupings; JavaScript clients serializing BigInt targets as strings with an 'n' suffix ("123n") after JSON.stringify quirks.
Related errors
- failed to convert element %d (%s) to int64: %w
- parameter %s: failed to convert element %d (%s) to int64: %w
- parameter %s is not of type string, is %T
- parameter %s could not be coerced to []string, is %T
- parameter %s could not be coerced to []int64, is %T
AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15).
Data as JSON: /api/errors/a9119ff2873c1d52.
Report an issue: GitHub.