{"record":{"id":"a75d4bc962581bba","repo":"JuliusBrussee/caveman","slug":"rewriter-unsupported-provider-q","errorCode":null,"errorMessage":"rewriter: unsupported provider %q","messagePattern":"rewriter: unsupported provider %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rewriter/rewriter.go","lineNumber":130,"sourceCode":"type Result struct {\n\tRewritten    []byte // includes trailing recovery-pointer line; empty when !Accepted\n\tAccepted     bool\n\tRejectReason string // non-empty when !Accepted; e.g. \"below_theta\", \"gate_failure_tokens\", \"api_error\"\n\tInputTokens  int    // rewriter's own metered usage, for cost netting\n\tOutputTokens int\n\t// CandidateTokens is the inferred size of what the model produced, reported\n\t// on rejected calls so a corpus study can size the rewrites the gate threw\n\t// away. The bytes themselves never leave on a rejection.\n\tCandidateTokens int\n}\n\n// New validates cfg and returns a Client. An unknown provider is an error\n// rather than a default: a silently mis-routed rewriter would produce bytes no\n// gate was designed for.\nfunc New(cfg Config) (*Client, error) {\n\tprovider := strings.ToLower(strings.TrimSpace(cfg.Provider))\n\tif provider != providerAnthropic && provider != providerOpenAI {\n\t\treturn nil, fmt.Errorf(\"rewriter: unsupported provider %q\", cfg.Provider)\n\t}\n\tmodel := strings.TrimSpace(cfg.Model)\n\tif model == \"\" {\n\t\treturn nil, errors.New(\"rewriter: model is required\")\n\t}\n\tif strings.TrimSpace(cfg.APIKey) == \"\" {\n\t\treturn nil, errors.New(\"rewriter: api key is required\")\n\t}\n\ttheta := cfg.Theta\n\tif theta == 0 {\n\t\ttheta = DefaultTheta\n\t}\n\tif theta < 0 {\n\t\treturn nil, fmt.Errorf(\"rewriter: theta must not be negative, got %d\", theta)\n\t}\n\tdoer := cfg.HTTPDoer\n\tif doer == nil {\n\t\tdoer = http.DefaultClient.Do","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/rewriter/rewriter.go#L112-L148","documentation":"rewriter.New validates the Config.Provider field and only accepts the known providers (anthropic, openai, compared case-insensitively after trimming whitespace). Any other value returns this error rather than defaulting, because a silently mis-routed rewriter would produce bytes no gate was designed for.","triggerScenarios":"Calling rewriter.New(Config{Provider: ...}) with a provider string that is not \"anthropic\" or \"openai\" (after ToLower+TrimSpace) — e.g. \"azure\", \"openai-chat\", an empty string, or a typo like \"anthropicc\".","commonSituations":"Config wired from YAML/env where the provider name comes from a free-form field; renaming providers in an internal config without updating the rewriter config; passing a provider constant from another library; typos in test fixtures (newTestClient exercises this).","solutions":["Set cfg.Provider to exactly \"anthropic\" or \"openai\" (case/whitespace are normalized, so \"OpenAI \" is fine)","Validate the config value at load time against the same allowed set before constructing the client","Check where the value originates (env var, flag, config file) for typos or stale values","Add your provider support upstream if you genuinely need another vendor — the client only implements these two"],"exampleFix":"// before\nclient, err := rewriter.New(rewriter.Config{Provider: cfg.LLMVendor}) // \"bedrock\"\n// after\nprovider := strings.ToLower(strings.TrimSpace(cfg.LLMVendor))\nif provider != \"anthropic\" && provider != \"openai\" {\n    provider = \"openai\" // or fail fast with a clear config error\n}\nclient, err := rewriter.New(rewriter.Config{Provider: provider})","handlingStrategy":"validation","validationCode":"func validProvider(p string) bool {\n    switch strings.ToLower(strings.TrimSpace(p)) {\n    case \"anthropic\", \"openai\":\n        return true\n    }\n    return false\n}\nif !validProvider(cfg.Provider) { return nil, fmt.Errorf(\"provider %q not in {anthropic, openai}\", cfg.Provider) }","typeGuard":null,"tryCatchPattern":"client, err := rewriter.New(cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"unsupported provider\") {\n        return fmt.Errorf(\"config: provider must be anthropic or openai, got %q\", cfg.Provider)\n    }\n    return err\n}","preventionTips":["Use a typed enum/constant for provider instead of a free string","Validate provider at config-load time, not at client construction","Keep provider names in one place to avoid drift between config and code","Trim/case-normalize at the config boundary (New does this too)"],"tags":["config","validation","go","provider"],"backgroundTag":"unsupported-enum-value","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"}