{"record":{"id":"292befc3ef0991a9","repo":"JuliusBrussee/caveman","slug":"provider-q-has-no-configured-upstream-url","errorCode":null,"errorMessage":"provider %q has no configured upstream URL","messagePattern":"provider %q has no configured upstream URL","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/providers/adapter.go","lineNumber":468,"sourceCode":"\tfor _, route := range b.Routes {\n\t\t// Routes ending in '/' are explicit subtree mounts (for example\n\t\t// /compat/ and /azure/). Every other route is exact. Treating all routes\n\t\t// as prefixes made /v1/responses-anything and /v1/messages/unknown valid\n\t\t// proxy surfaces, violating the gateway's closed route allowlist.\n\t\tif path == route || strings.HasSuffix(route, \"/\") && strings.HasPrefix(path, route) {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\nfunc (b Base) ResolveUpstreamURL(ctx context.Context, req *http.Request, route RouteContext) (*url.URL, error) {\n\tbaseURL := b.BaseURL\n\tif route.BaseURL != \"\" {\n\t\tbaseURL = route.BaseURL\n\t}\n\tif strings.TrimSpace(baseURL) == \"\" {\n\t\treturn nil, fmt.Errorf(\"provider %q has no configured upstream URL\", b.Provider)\n\t}\n\tbase, err := url.Parse(baseURL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !base.IsAbs() || base.Hostname() == \"\" {\n\t\treturn nil, fmt.Errorf(\"provider %q upstream URL must be absolute\", b.Provider)\n\t}\n\tpath := req.URL.Path\n\tfor _, prefix := range []string{\"/openai\", \"/anthropic\", \"/gemini\", \"/compat/stub\", \"/compat/openai-compatible\"} {\n\t\tpath = strings.TrimPrefix(path, prefix)\n\t}\n\tif strings.HasPrefix(req.URL.Path, \"/azure/\") {\n\t\tpath = strings.TrimPrefix(req.URL.Path, \"/azure\")\n\t}\n\tbase.Path = strings.TrimRight(base.Path, \"/\") + path\n\tbase.RawQuery = req.URL.RawQuery\n\treturn base, nil","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/providers/adapter.go#L450-L486","documentation":"Base.ResolveUpstreamURL determines the upstream target for a provider request from BaseURL or the per-request RouteContext.BaseURL. If, after route overrides, the base URL is empty/whitespace, there is no server to proxy to, so it errors naming the provider. This prevents building requests against a nil base.","triggerScenarios":"Calling a provider adapter whose BaseURL was never set and whose RouteContext.BaseURL is empty — e.g. constructing Base{} without configuration, or a route entry with a blank BaseURL field overriding a valid default with \"\".","commonSituations":"Config file missing the upstream/base-url key for a custom provider; stub/test adapters registered without a base URL; route table entries accidentally blank after refactoring config loading.","solutions":["Set the provider's BaseURL in configuration (e.g. https://api.openai.com)","Populate RouteContext.BaseURL for per-route overrides instead of leaving it empty","Verify config loading actually assigns the base URL field (don't shadow with \"\")","Log/validate the provider config at startup so missing URLs are caught early"],"exampleFix":"// before\nadapter := providers.Base{Provider: \"openai\"} // BaseURL unset\n// after\nadapter := providers.Base{Provider: \"openai\", BaseURL: \"https://api.openai.com\"}","handlingStrategy":"validation","validationCode":"func ensureBaseURL(b providers.Base, route providers.RouteContext) error {\n\turl := route.BaseURL\n\tif url == \"\" { url = b.BaseURL }\n\tif strings.TrimSpace(url) == \"\" {\n\t\treturn fmt.Errorf(\"provider %q needs a BaseURL\", b.Provider)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"u, err := adapter.ResolveUpstreamURL(ctx, req, route)\nif err != nil && strings.Contains(err.Error(), \"no configured upstream URL\") {\n\t// fail request with 500 + config guidance\n}","preventionTips":["Validate provider config (BaseURL present) at startup, before serving traffic","Never assign empty-string route overrides over valid defaults","Add config schema validation requiring base_url for each provider"],"tags":["configuration","proxy","routing"],"backgroundTag":"missing-required-config-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}