Skip to content

Commit 39bd464

Browse files
returns error from parsing string to int64
1 parent 2652525 commit 39bd464

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

pkg/github/server.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,24 @@ func OptionalStringArrayParam(r mcp.CallToolRequest, p string) ([]string, error)
203203
}
204204
}
205205

206-
func convertStringSliceToBigIntSlice(s []string) []int64 {
206+
func convertStringSliceToBigIntSlice(s []string) ([]int64, error) {
207207
int64Slice := make([]int64, len(s))
208208
for i, str := range s {
209-
int64Slice[i] = convertStringToBigInt(str, 0)
209+
val, err := convertStringToBigInt(str, 0)
210+
if err != nil {
211+
return nil, fmt.Errorf("failed to convert element %d (%s) to int64: %w", i, str, err)
212+
}
213+
int64Slice[i] = val
210214
}
211-
return int64Slice
215+
return int64Slice, nil
212216
}
213217

214-
func convertStringToBigInt(s string, def int64) int64 {
218+
func convertStringToBigInt(s string, def int64) (int64, error) {
215219
v, err := strconv.ParseInt(s, 10, 64)
216220
if err != nil {
217-
return def
221+
return def, fmt.Errorf("failed to convert string %s to int64: %w", s, err)
218222
}
219-
return v
223+
return v, nil
220224
}
221225

222226
// OptionalBigIntArrayParam is a helper function that can be used to fetch a requested parameter from the request.
@@ -233,15 +237,19 @@ func OptionalBigIntArrayParam(r mcp.CallToolRequest, p string) ([]int64, error)
233237
case nil:
234238
return []int64{}, nil
235239
case []string:
236-
return convertStringSliceToBigIntSlice(v), nil
240+
return convertStringSliceToBigIntSlice(v)
237241
case []any:
238242
int64Slice := make([]int64, len(v))
239243
for i, v := range v {
240244
s, ok := v.(string)
241245
if !ok {
242246
return []int64{}, fmt.Errorf("parameter %s is not of type string, is %T", p, v)
243247
}
244-
int64Slice[i] = convertStringToBigInt(s, 0)
248+
val, err := convertStringToBigInt(s, 0)
249+
if err != nil {
250+
return []int64{}, fmt.Errorf("parameter %s: failed to convert element %d (%s) to int64: %w", p, i, s, err)
251+
}
252+
int64Slice[i] = val
245253
}
246254
return int64Slice, nil
247255
default:

0 commit comments

Comments
 (0)