crowdsecurity/crowdsec · error

while parsing dsn '%s': %w

Error message

while parsing dsn '%s': %w

What it means

ConfigureByDSN of the loki source parses the DSN with url.Parse; a syntactically invalid URL (e.g. bad characters or malformed host) cannot be turned into a Loki client endpoint, so configuration fails.

Source

Thrown at pkg/acquisition/modules/loki/config.go:125

		FailMaxDuration: l.Config.MaxFailureDuration,
	}

	l.Client = lokiclient.NewLokiClient(clientConfig)
	l.Client.Logger = logger.WithFields(log.Fields{"component": "lokiclient", "source": l.Config.URL})

	return nil
}

func (l *Source) ConfigureByDSN(_ context.Context, dsn string, labels map[string]string, logger *log.Entry, uuid string) error {
	l.logger = logger
	l.Config = Configuration{}
	l.Config.Mode = configuration.CAT_MODE
	l.Config.Labels = labels
	l.Config.UniqueId = uuid

	u, err := url.Parse(dsn)
	if err != nil {
		return fmt.Errorf("while parsing dsn '%s': %w", dsn, err)
	}

	if u.Scheme != "loki" {
		return fmt.Errorf("invalid DSN %s for loki source, must start with loki://", dsn)
	}

	if u.Host == "" {
		return errors.New("empty loki host")
	}

	scheme := "http"

	params := u.Query()
	if q := params.Get("ssl"); q != "" {
		scheme = "https"
	}

	if q := params.Get("query"); q != "" {

View on GitHub (pinned to 909b515798)

Solutions

  1. Correct the loki:// DSN syntax, e.g. loki://host:3100/loki/api/v1/query_range
  2. Check for stray characters or invalid URL escapes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/acquisition/modules/loki/config.go:125 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/58ea4a13c5e651cb. Report an issue: GitHub.