{"record":{"id":"904cd814fef69c6f","repo":"alibaba/open-code-review","slug":"invalid-url-for-s-w","errorCode":null,"errorMessage":"invalid URL for %s: %w","messagePattern":"invalid URL for (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":620,"sourceCode":"\t\t}\n\t\tcfg.Llm.RetryCodes = codes\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown config key: %s\\nSupported keys: %s\\nProvider fields: api_key, api_key_cmd, url, protocol, model, models, auth_header, extra_body, extra_headers, retry_codes, aws_region, aws_profile\\nProtocol values: anthropic, anthropic-bedrock, openai, openai-responses\\nMCP server fields: type, command, args, env, url, headers, tools, setup\", key, strings.Join(supportedConfigKeys, \", \"))\n\t}\n\treturn nil\n}\n\nfunc applyProviderField(providerName string, entry *ProviderEntry, field, key, value string) error {\n\tswitch field {\n\tcase \"api_key\":\n\t\tentry.APIKey = value\n\tcase \"api_key_cmd\":\n\t\tentry.APIKeyCmd = value\n\tcase \"url\":\n\t\ttrimmedURL := strings.TrimSpace(value)\n\t\tif trimmedURL != \"\" {\n\t\t\tif err := validateBaseURL(trimmedURL); err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid URL for %s: %w\", key, err)\n\t\t\t}\n\t\t}\n\t\tentry.URL = trimmedURL\n\tcase \"protocol\":\n\t\tnormalized := llm.NormalizeProtocol(value)\n\t\tif err := llm.ValidateProtocol(normalized); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tentry.Protocol = normalized\n\t\t// Switching away from bedrock leaves aws_region/aws_profile as dead\n\t\t// config that reads as applied but nothing reads it — clear both, the\n\t\t// same way the TUI drops url/api_key/auth_header when switching onto\n\t\t// bedrock (see cpAmbientProtocol in provider_tui.go).\n\t\tif normalized != llm.ProtocolAnthropicBedrock && (entry.AWSRegion != \"\" || entry.AWSProfile != \"\") {\n\t\t\tfmt.Fprintf(os.Stderr, \"[ocr] WARNING: clearing aws_region/aws_profile on %q: protocol %q does not use the AWS credential chain\\n\", providerName, normalized)\n\t\t\tentry.AWSRegion = \"\"\n\t\t\tentry.AWSProfile = \"\"\n\t\t}","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L602-L638","documentation":"applyProviderField validates a provider's url field with validateBaseURL and wraps any failure as \"invalid URL for <key>: %w\", where key is the full dotted path (e.g. providers.openai.url). Empty strings are allowed (meaning unset); anything else must parse as a valid base URL.","triggerScenarios":"`ocr config set providers.<name>.url <value>` or the equivalent custom_providers path, with a value lacking a scheme (\"localhost:8080\"), containing spaces, or otherwise rejected by validateBaseURL.","commonSituations":"Forgetting https://; leaving a placeholder like <YOUR_URL> in a script; trailing whitespace or typos; pointing at a local gateway without the scheme.","solutions":["Include the scheme: `ocr config set providers.openai.url https://api.openai.com`","Trim stray whitespace/quotes from the value","Check the wrapped validateBaseURL message for the specific defect","Leave the value empty (\"\" intentionally clears the URL) rather than passing a placeholder"],"exampleFix":"// before\nocr config set providers.openai.url localhost:8080\n// after\nocr config set providers.openai.url http://localhost:8080","handlingStrategy":"validation","validationCode":"u := strings.TrimSpace(url)\nif u != \"\" {\n    parsed, err := neturl.Parse(u)\n    if err != nil || (parsed.Scheme != \"http\" && parsed.Scheme != \"https\") || parsed.Host == \"\" {\n        return fmt.Errorf(\"provider url must include http(s):// and a host, got %q\", u)\n    }\n}\n_ = runConfigSet(\"providers.openai.url\", u)","typeGuard":null,"tryCatchPattern":"if err := runConfigSet(\"providers.openai.url\", u); err != nil {\n    if strings.Contains(err.Error(), \"invalid URL for\") {\n        fmt.Fprintf(os.Stderr, \"%q rejected: include scheme and host, e.g. https://api.example.com\\n\", u)\n    }\n}","preventionTips":["Always include http:// or https://","Trim whitespace and remove shell quotes before passing","Never leave placeholders like <YOUR_URL> in scripted configs","Pass \"\" intentionally to clear the field"],"tags":["config","url","validation","cli"],"backgroundTag":"invalid-url","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}