fix: listTasks query parsing - #362
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors query parameter parsing in a2asrv/rest.go by replacing inline parsing logic with dedicated helper functions (parseListTasksQueryParams, parseHistoryLength, and parseStatusTimestampAfter) and adds comprehensive unit tests in a2asrv/rest_test.go to verify query parsing. The reviewer suggested simplifying the parseHistoryLength and parseStatusTimestampAfter helper functions by returning early when the query parameter is empty, which improves readability and avoids declaring unnecessary pointer variables.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| func parseHistoryLength(query url.Values) (*int, error) { | ||
| historyLengthRaw := query.Get("historyLength") | ||
| var historyLength *int | ||
| if historyLengthRaw != "" { | ||
| val, err := strconv.Atoi(historyLengthRaw) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| historyLength = &val | ||
| } | ||
| return historyLength, nil | ||
| } |
There was a problem hiding this comment.
This helper function can be simplified by returning early when the query parameter is empty. This avoids declaring an unnecessary pointer variable and makes the logic more direct and readable.
func parseHistoryLength(query url.Values) (*int, error) {
raw := query.Get("historyLength")
if raw == "" {
return nil, nil
}
val, err := strconv.Atoi(raw)
if err != nil {
return nil, err
}
return &val, nil
}| func parseStatusTimestampAfter(query url.Values) (*time.Time, error) { | ||
| statusTimestampAfterRaw := query.Get("statusTimestampAfter") | ||
| var statusTimestampAfter *time.Time | ||
| if statusTimestampAfterRaw != "" { | ||
| val, err := time.Parse(time.RFC3339Nano, statusTimestampAfterRaw) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| statusTimestampAfter = &val | ||
| } | ||
| return statusTimestampAfter, nil | ||
| } |
There was a problem hiding this comment.
This helper function can be simplified by returning early when the query parameter is empty. This avoids declaring an unnecessary pointer variable and makes the logic more direct and readable.
func parseStatusTimestampAfter(query url.Values) (*time.Time, error) {
raw := query.Get("statusTimestampAfter")
if raw == "" {
return nil, nil
}
val, err := time.Parse(time.RFC3339Nano, raw)
if err != nil {
return nil, err
}
return &val, nil
}
GET /tasks?historyLength=Nand?statusTimestampAfter=...were silentlydropped by the REST
ListTaskshandler. Theparseclosure dispatched ontarget type with a type switch, but
*int/*time.Timefields onListTasksRequestproduced**int/**time.Timearguments that no casematched — so the values never reached the request.
Replaced the type-switch
parseclosure with a typedparseQueryParamshelper that returns
(*a2a.ListTasksRequest, error).Extracted
parseHistoryLengthandparseStatusTimestampAfterhelpers,reused by
handleGetTaskandhandleListTasks.Added new test to verify correctly parsed ListTasksRequest reaching to handler
Extended
TestREST_ListTasksParseErrorswithhistoryLengthandstatusTimestampAfterinvalid-value cases.