{"record":{"id":"f743b15cae018a7b","repo":"alibaba/open-code-review","slug":"invalid-base-url-q-w","errorCode":null,"errorMessage":"invalid Base URL %q: %w","messagePattern":"invalid Base URL %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/provider_cmd.go","lineNumber":453,"sourceCode":"}\n\nfunc maskKey(key string) string {\n\tif key == \"\" {\n\t\treturn \"(not set)\"\n\t}\n\tif len(key) <= 8 {\n\t\treturn \"***\"\n\t}\n\treturn key[:4] + \"***\" + key[len(key)-4:]\n}\n\n// validateBaseURL checks that a provider Base URL has an http or https scheme\n// and a non-empty host, giving the user immediate feedback rather than\n// a runtime failure when the LLM client tries to use it.\nfunc validateBaseURL(raw string) error {\n\tparsed, err := url.Parse(raw)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid Base URL %q: %w\", raw, err)\n\t}\n\tif parsed.Scheme != \"http\" && parsed.Scheme != \"https\" {\n\t\treturn fmt.Errorf(\"Base URL must use http or https scheme, got %q\", parsed.Scheme)\n\t}\n\tif parsed.Host == \"\" {\n\t\treturn fmt.Errorf(\"Base URL %q must include a host\", raw)\n\t}\n\treturn nil\n}\n","sourceCodeStart":435,"sourceCodeEnd":463,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/provider_cmd.go#L435-L463","documentation":"validateBaseURL parses a provider Base URL with url.Parse before saving; if parsing itself fails, the error is wrapped as \"invalid Base URL %q\". This gives immediate feedback that the URL string is malformed rather than failing later at LLM-client request time.","triggerScenarios":"ocr config provider set/update (applyProviderField) called with a Base URL that Go's url.Parse rejects — e.g. control characters, invalid percent-encoding, or other unparseable syntax.","commonSituations":"Pasting a URL with stray whitespace/control characters or unescaped special characters from documentation; typos introducing invalid escape sequences like %zz.","solutions":["Re-enter the Base URL with valid URL syntax and no stray control characters","Percent-encode special characters properly (e.g. spaces as %20)","Check the wrapped inner error (url.Parse's message) for the exact syntax problem","Use a plain scheme://host[:port][/path] form, e.g. https://api.example.com/v1"],"exampleFix":"// before\n$ ocr config provider set base-url \"https://api.example.com/v1%zz\"\n// error: invalid Base URL ...: invalid URL escape \"%zz\"\n// after\n$ ocr config provider set base-url \"https://api.example.com/v1\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(strings.TrimSpace(raw))\nif err != nil { return fmt.Errorf(\"invalid Base URL %q: %w\", raw, err) }\nif u.Scheme != \"http\" && u.Scheme != \"https\" { return fmt.Errorf(\"scheme must be http/https\") }\nif u.Host == \"\" { return fmt.Errorf(\"host required\") }","typeGuard":"func isValidBaseURL(raw string) bool {\n    u, err := url.Parse(raw)\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"if err := applyProviderField(...); err != nil {\n    if strings.Contains(err.Error(), \"invalid Base URL\") {\n        fmt.Fprintf(os.Stderr, \"check URL syntax; underlying: %v\\n\", errors.Unwrap(err))\n    }\n    return err\n}","preventionTips":["Paste URLs without trailing whitespace or control characters","Percent-encode special characters in paths","Sanity-check the URL in a browser or curl before configuring","Use scheme://host[:port]/path form from vendor docs verbatim"],"tags":["validation","url","config"],"backgroundTag":"invalid-url-syntax","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}