You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Split out from PR #47 review (CodeRabbit + Copilot both flagged it).
Problem
`pkg/listutil/listutil.go` `FetchPaginated` returns `(nil, nil)` whenever the underlying GET fails with a `cmdutil.IsOptionalResourceError` (HTTP 400 or 404):
This was inherited from `configutil`'s original unexported helper, where the lenience is intentional: in non-stream deployments `stream_routes` (and similarly `protos`, `secrets`) return 400/404, and `config dump` should treat those as "this resource is not in use here" rather than fail outright.
Promoting that helper into a shared `pkg/listutil` package as part of #42 generalized the lenience to every caller, which is wrong:
`route list` aggregation can hide real errors. If a service is deleted between the `/services` enumeration and the per-service `/routes` fetch, the 404 is silently dropped and the user sees fewer routes with no indication.
`config dump` of required resources can produce partial output. A 400 on `/services` or `/consumers` would currently return `nil` instead of failing — `config sync` could then diff an empty remote against a populated local and propose mass deletions.
Only convert optional-resource errors into `(nil, nil)` when `allowOptional == true`. Pass `true` only at the call sites where the resource is genuinely optional:
Split out from PR #47 review (CodeRabbit + Copilot both flagged it).
Problem
`pkg/listutil/listutil.go` `FetchPaginated` returns `(nil, nil)` whenever the underlying GET fails with a `cmdutil.IsOptionalResourceError` (HTTP 400 or 404):
```go
body, err := client.Get(path, query)
if err != nil {
if cmdutil.IsOptionalResourceError(err) {
return nil, nil
}
return nil, err
}
```
This was inherited from `configutil`'s original unexported helper, where the lenience is intentional: in non-stream deployments `stream_routes` (and similarly `protos`, `secrets`) return 400/404, and `config dump` should treat those as "this resource is not in use here" rather than fail outright.
Promoting that helper into a shared `pkg/listutil` package as part of #42 generalized the lenience to every caller, which is wrong:
Proposed fix
Add an explicit `allowOptional bool` parameter:
```go
func FetchPaginated[T any](
client *api.Client,
path string,
extraQuery map[string]string,
allowOptional bool,
) ([]T, error)
```
Only convert optional-resource errors into `(nil, nil)` when `allowOptional == true`. Pass `true` only at the call sites where the resource is genuinely optional:
Thread the same flag through `FetchRoutesForServices` (default `false` so 404 on a per-service `/routes` fetch propagates).
Update the doc comment to describe the actual contract.
Tests
Scope
This is a refactor across:
Filed as a follow-up to PR #47 so the original change can land focused on the route-list UX fix.