{"record":{"id":"983525d1ca107975","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-parse-server-url-q-w","errorCode":null,"errorMessage":"cannot parse server url=%q: %w","messagePattern":"cannot parse server url=%q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/promscrape/discovery/kuma/api.go","lineNumber":113,"sourceCode":"\t\treturn nil, fmt.Errorf(\"cannot discover Kuma targets: %w\", err)\n\t}\n\tcfg.wg.Go(func() {\n\t\tcfg.runTargetsWatcher(ctx)\n\t})\n\n\treturn cfg, nil\n}\n\nfunc getAPIServerPath(serverURL string) (string, string, error) {\n\tif serverURL == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"missing server url\")\n\t}\n\tif !strings.Contains(serverURL, \"://\") {\n\t\tserverURL = \"http://\" + serverURL\n\t}\n\tpsu, err := url.Parse(serverURL)\n\tif err != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"cannot parse server url=%q: %w\", serverURL, err)\n\t}\n\tapiServer := fmt.Sprintf(\"%s://%s\", psu.Scheme, psu.Host)\n\tapiPath := psu.Path\n\tif !strings.HasSuffix(apiPath, \"/\") {\n\t\tapiPath += \"/\"\n\t}\n\tapiPath += \"v3/discovery:monitoringassignments\"\n\tif psu.RawQuery != \"\" {\n\t\tapiPath += \"?\" + psu.RawQuery\n\t}\n\treturn apiServer, apiPath, nil\n}\n\nfunc (cfg *apiConfig) runTargetsWatcher(ctx context.Context) {\n\tticker := time.NewTicker(*SDCheckInterval)\n\tdefer ticker.Stop()\n\n\tdoneCh := ctx.Done()","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/promscrape/discovery/kuma/api.go#L95-L131","documentation":"getAPIServerPath parses the (scheme-prefixed) server URL with net/url.Parse. If parsing fails, the error is wrapped with this message including the full server string. It means the Kuma control-plane URL is syntactically invalid even after the automatic http:// prefixing.","triggerScenarios":"Server string containing spaces, control characters, stray brackets/quotes, or otherwise failing url.Parse (e.g. `server: \"http://kuma cp:5676\"`), when getAPIServerPath runs.","commonSituations":"Unquoted YAML values with special characters; copy-pasted URLs with trailing whitespace; IPv6 literal addresses missing brackets; templating artifacts left in the URL.","solutions":["Fix the `server` value so it parses as a URL (quote it in YAML, remove spaces/control chars)","Wrap IPv6 hosts in brackets: `http://[::1]:5676`","Pre-validate with Go url.Parse or any URL validator before deploying the config","Read the wrapped error to see url.Parse's exact complaint (e.g. invalid port, invalid character)"],"exampleFix":"# before\nserver: http://kuma cp:5676   # unquoted, contains space\n# after\nserver: \"http://kuma-cp:5676\"","handlingStrategy":"validation","validationCode":"func validKumaURL(server string) error {\n    if server == \"\" {\n        return errors.New(\"missing server url\")\n    }\n    u := server\n    if !strings.Contains(u, \"://\") {\n        u = \"http://\" + u\n    }\n    psu, err := url.Parse(u)\n    if err != nil {\n        return fmt.Errorf(\"invalid server url %q: %w\", server, err)\n    }\n    if psu.Host == \"\" {\n        return fmt.Errorf(\"server url %q has no host\", server)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"ac, err := kuma.NewSDConfig(sdc)\nif err != nil {\n    if strings.Contains(err.Error(), \"cannot parse server url\") {\n        log.Errorf(\"malformed kuma server URL: %v\", err)\n    }\n    return err\n}","preventionTips":["Quote server URLs in YAML files","Remove whitespace/control characters pasted into URLs","Bracket IPv6 literals: http://[::1]:5676","Run url.Parse-based validation in CI on scrape configs"],"tags":["kuma","config","url-parsing","promscrape","service-discovery"],"backgroundTag":"invalid-url-config","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}