crowdsecurity/crowdsec · error

url is required

Error message

url is required

What it means

Constructor validation in NewLongPollClient. A LongPollClientConfig must carry a non-zero target url.URL; without it the client would long-poll an empty endpoint, so construction fails immediately. Called via NewPAPI when wiring up the PAPI client.

Source

Thrown at pkg/longpollclient/client.go:265

		c.logger.Tracef("got response: %+v", pollResp)

		if pollResp.ErrorMessage != "" {
			if pollResp.ErrorMessage == timeoutMessage {
				c.logger.Debugf("got timeout message")
				break
			}
			log.Errorf("longpoll API error message: %s", pollResp.ErrorMessage)
			break
		}
		evts = append(evts, pollResp.Events...)
	}
	return evts, nil
}

func NewLongPollClient(config LongPollClientConfig) (*LongPollClient, error) {
	var logger *log.Entry
	if config.Url == (url.URL{}) {
		return nil, errors.New("url is required")
	}
	if config.Logger == nil {
		logger = log.WithField("component", "longpollclient")
	} else {
		logger = config.Logger.WithFields(log.Fields{
			"component": "longpollclient",
			"url":       config.Url.String(),
		})
	}

	return &LongPollClient{
		url:        config.Url,
		logger:     logger,
		httpClient: config.HttpClient,
	}, nil
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Set the Url field, e.g. url.Parse("https://papi.api.crowdsec.net") before calling the constructor.
  2. Check NewPAPI's caller path to ensure configuration loading (profiles/API URL) succeeded and was passed through.
  3. Guard construction: parse and validate the URL, skip/abort the PAPI client if absent.

Example fix

// before
cfg := LongPollClientConfig{Logger: logger}
client, _ := NewLongPollClient(cfg)
// after
u, err := url.Parse("https://papi.api.crowdsec.net")
if err != nil { return err }
cfg := LongPollClientConfig{Logger: logger, Url: *u}
client, err := NewLongPollClient(cfg)
Defensive patterns

Strategy: validation

Validate before calling

if cfg.Url == (url.URL{}) {
    return errors.New("longpollclient config requires Url")
}
if _, err := url.Parse(cfg.Url.String()); err != nil {
    return fmt.Errorf("invalid longpoll url: %w", err)
}

Type guard

func hasURL(c LongPollClientConfig) bool { return c.Url != url.URL{} }

Try / catch

client, err := NewLongPollClient(cfg)
if err != nil {
    return fmt.Errorf("PAPI client init failed: %w", err)
}

Prevention

When it happens

Trigger: Calling NewLongPollClient (directly or through NewPAPI) with LongPollClientConfig{} or a config whose Url field was never populated (url.URL zero value).

Common situations: Programmatic use of the longpollclient package with a partially filled config struct, or an upstream setup function that fails to load the PAPI endpoint from configuration before constructing the client.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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