{"record":{"id":"25f25d0464440954","repo":"crowdsecurity/crowdsec","slug":"invalid-loki-url-q-w","errorCode":null,"errorMessage":"invalid Loki URL %q: %w","messagePattern":"invalid Loki URL %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go","lineNumber":54,"sourceCode":"\tQuery      string\n\tHeaders    map[string]string\n\n\tUsername string\n\tPassword string\n\n\tSince time.Duration\n\tUntil time.Duration\n\n\tFailMaxDuration time.Duration\n\n\tDelayFor int\n\tLimit    int\n}\n\nfunc updateURI(uri string, lq LokiQueryRangeResponse, infinite bool) (string, error) {\n\tu, err := url.Parse(uri)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"invalid Loki URL %q: %w\", uri, err)\n\t}\n\tqueryParams := u.Query()\n\n\tvar maxTS time.Time\n\tfor _, stream := range lq.Data.Result {\n\t\tfor _, entry := range stream.Entries {\n\t\t\tif entry.Timestamp.After(maxTS) {\n\t\t\t\tmaxTS = entry.Timestamp\n\t\t\t}\n\t\t}\n\t}\n\n\tif !maxTS.IsZero() {\n\t\t// +1 the last timestamp to avoid getting the same result again.\n\t\tqueryParams.Set(\"start\", strconv.FormatInt(maxTS.UnixNano()+1, 10))\n\t}\n\t// When maxTS.IsZero() (no results), keep the existing start to avoid\n\t// re-fetching already-processed logs. Only end is moved forward below.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go#L36-L72","documentation":"updateURI re-parses the current query_range URI to append new start/next parameters when paginating through results. If the stored URI cannot be parsed by url.Parse, this error wraps the cause and aborts the query loop.","triggerScenarios":"The URI constructed from the DSN (getURLFor + query params) is malformed — e.g. invalid percent-escapes or a corrupted URL string built from a bad datasource config.","commonSituations":"Malformed DSN host with stray characters; control characters or unencoded '%' in query parameters.","solutions":["Fix the datasource URL in the DSN so it is a valid absolute URL (scheme://host:port/path?params)","Percent-encode special characters ('%' as '%25', spaces as '%20')","Verify with a quick url.Parse in Go or a browser that the URL is well formed"],"exampleFix":"// before\nloki://localhost:3100/loki/api/v1/query_range?query={job=\"app\"}\n// after\nloki://localhost:3100/loki/api/v1/query_range?query=%7Bjob%3D%22app%22%7D","handlingStrategy":"validation","validationCode":"if _, err := url.Parse(dsnURL); err != nil {\n    return fmt.Errorf(\"datasource URL invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Percent-encode LogQL selectors and special characters in query params","Test the final URL with curl before adding to acquis.yaml"],"tags":["loki","url","parsing"],"backgroundTag":"invalid-url-format","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}