crowdsecurity/crowdsec · error

building query: %w

Error message

building query: %w

What it means

Returned by AllowlistsService.List when go-querystring fails to serialize the AllowlistListOpts struct into URL query parameters. A generic guard over the opts input; in practice it only fires if a url tag on the struct is invalid.

Source

Thrown at pkg/apiclient/allowlists_service.go:26

	qs "github.com/google/go-querystring/query"
	log "github.com/sirupsen/logrus"

	"github.com/crowdsecurity/crowdsec/pkg/models"
)

type AllowlistsService service

type AllowlistListOpts struct {
	WithContent bool `url:"with_content,omitempty"`
}

func (s *AllowlistsService) List(ctx context.Context, opts AllowlistListOpts) (*models.GetAllowlistsResponse, *Response, error) {
	u := s.client.URLPrefix + "/allowlists"

	params, err := qs.Values(opts)
	if err != nil {
		return nil, nil, fmt.Errorf("building query: %w", err)
	}

	u += "?" + params.Encode()

	req, err := s.client.PrepareRequest(ctx, http.MethodGet, u, nil)
	if err != nil {
		return nil, nil, err
	}

	allowlists := &models.GetAllowlistsResponse{}

	resp, err := s.client.Do(ctx, req, allowlists)
	if err != nil {
		return nil, resp, err
	}

	return allowlists, resp, nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Use valid values for AllowlistListOpts (e.g. WithContent bool)
  2. Check for corrupted option structs passed by the caller
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/apiclient/allowlists_service.go:26 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/2c65572c769d05f0. Report an issue: GitHub.