{"record":{"id":"650b447b1b86f12e","repo":"chenhg5/cc-connect","slug":"providerproxy-parse-target-w","errorCode":null,"errorMessage":"providerproxy: parse target: %w","messagePattern":"providerproxy: parse target: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/providerproxy.go","lineNumber":39,"sourceCode":"// Some providers (e.g. SiliconFlow) don't support thinking.type \"adaptive\"\n// sent by Claude Code 2.x. The proxy rewrites the thinking field to\n// the configured override value before forwarding.\ntype ProviderProxy struct {\n\ttargetURL        string\n\tthinkingOverride string\n\tlistener         net.Listener\n\tserver           *http.Server\n\tonce             sync.Once\n}\n\n// NewProviderProxy creates and starts a local reverse proxy for the\n// given upstream URL. thinkingOverride controls what thinking.type to\n// rewrite \"adaptive\" to (e.g. \"disabled\" or \"enabled\").\n// Returns the local URL to use as ANTHROPIC_BASE_URL.\nfunc NewProviderProxy(targetURL, thinkingOverride string) (*ProviderProxy, string, error) {\n\ttarget, err := url.Parse(strings.TrimRight(targetURL, \"/\"))\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"providerproxy: parse target: %w\", err)\n\t}\n\n\tlistener, err := net.Listen(\"tcp\", \"127.0.0.1:0\")\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"providerproxy: listen: %w\", err)\n\t}\n\n\tproxy := httputil.NewSingleHostReverseProxy(target)\n\torigDirector := proxy.Director\n\tproxy.Director = func(req *http.Request) {\n\t\torigDirector(req)\n\t\treq.Host = target.Host\n\t}\n\tproxy.FlushInterval = -1 // flush SSE events immediately\n\n\toverride := thinkingOverride\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/providerproxy.go#L21-L57","documentation":"`NewProviderProxy` parses the upstream API base URL before starting a local reverse proxy; if `url.Parse` fails on the trimmed target, it returns `providerproxy: parse target: %w`. This means the configured ANTHROPIC_BASE_URL-style target is not a parsable URL, so no proxy can be started.","triggerScenarios":"Calling NewProviderProxy (via ensureProviderProxyLocked, e.g. when enabling provider proxying for an agent) with a targetURL that fails url.Parse — missing scheme with invalid characters, stray control characters, malformed percent-escapes.","commonSituations":"config.toml contains a hand-edited base_url with a typo (e.g. `htp://`, embedded space, unescaped `%`); environment variable holding the base URL is corrupted; shell quoting mangled the URL.","solutions":["Print the exact targetURL being passed and inspect it for typos or invisible characters.","Fix the base_url value in config.toml (must be a valid absolute URL, e.g. https://api.example.com).","Validate before use: `u, err := url.Parse(strings.TrimRight(cfg.BaseURL, \"/\")); err != nil { ... }`.","Re-export the environment variable if the value came from env and looks corrupted."],"exampleFix":"// before\nbaseURL := os.Getenv(\"ANTHROPIC_BASE_URL\")\nproxy, local, err := NewProviderProxy(baseURL, \"disabled\")\n\n// after\nbaseURL := strings.TrimSpace(os.Getenv(\"ANTHROPIC_BASE_URL\"))\nif u, err := url.Parse(baseURL); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid ANTHROPIC_BASE_URL %q\", baseURL)\n}\nproxy, local, err := NewProviderProxy(baseURL, \"disabled\")","handlingStrategy":"validation","validationCode":"func validBaseURL(s string) bool {\n    u, err := url.Parse(strings.TrimRight(strings.TrimSpace(s), \"/\"))\n    return err == nil && u.Scheme != \"\" && u.Host != \"\"\n}","typeGuard":null,"tryCatchPattern":"proxy, local, err := NewProviderProxy(targetURL, thinking)\nif err != nil {\n    return fmt.Errorf(\"starting provider proxy for %q: %w\", redactedURL, err)\n}","preventionTips":["Validate base URLs at config-load time, before any proxy is started.","Avoid hand-editing URLs in config.toml; copy exact values from provider docs.","Beware shell quoting when exporting base URL environment variables.","Redact tokens from URLs in logs when diagnosing parse failures."],"tags":["url","config","proxy","go"],"backgroundTag":"invalid-url-format","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}