{"record":{"id":"acda3ccdcb7bb3f3","repo":"vxcontrol/pentagi","slug":"invalid-provider-config-w","errorCode":null,"errorMessage":"invalid provider config: %w","messagePattern":"invalid provider config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/providers/providers.go","lineNumber":792,"sourceCode":"\t\terr    error\n\t\tresult database.Provider\n\t)\n\n\tprv, err := pc.db.GetUserProvider(ctx, database.GetUserProviderParams{\n\t\tID:     prvID,\n\t\tUserID: userID,\n\t})\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to get provider: %w\", err)\n\t}\n\tprvtype := provider.ProviderType(prv.Type)\n\n\tif config, err = pc.patchProviderConfig(prvtype, config); err != nil {\n\t\treturn result, fmt.Errorf(\"failed to patch provider config: %w\", err)\n\t}\n\n\tif err = config.Validate(); err != nil {\n\t\treturn result, fmt.Errorf(\"invalid provider config: %w\", err)\n\t}\n\n\trawConfig, err := json.Marshal(config)\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to marshal provider config: %w\", err)\n\t}\n\n\tresult, err = pc.db.UpdateUserProvider(ctx, database.UpdateUserProviderParams{\n\t\tID:     prvID,\n\t\tUserID: userID,\n\t\tName:   string(prvname),\n\t\tConfig: rawConfig,\n\t})\n\tif err != nil {\n\t\treturn result, fmt.Errorf(\"failed to update provider: %w\", err)\n\t}\n\n\treturn result, nil","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/providers/providers.go#L774-L810","documentation":"UpdateProvider validates the merged provider config with config.Validate() after patching it with defaults. If validation fails (missing model, bad credentials shape, invalid values for the provider type), the update is aborted and wrapped as \"invalid provider config: %w\". It means the supplied config is semantically invalid for this provider type even after defaults were applied.","triggerScenarios":"Calling UpdateProvider with a *pconfig.ProviderConfig whose fields fail Validate() — e.g. a nil model name, an empty API key where one is required, or a field combination invalid for the provider type stored in the DB row.","commonSituations":"Saving settings from the frontend where a required model/API-key field was left blank; switching a provider's model to an unset value; partial-update payloads that blank out required fields.","solutions":["Read the wrapped inner error from config.Validate() to see exactly which field failed","Ensure required fields (model name, API key, base URL) are non-empty before calling UpdateProvider","Call patchProviderConfig/CreateProvider flow first or pass a full config instead of a sparse one","Log the marshaled config (redacting secrets) to confirm what was actually validated"],"exampleFix":"// before\n_, err := ctrl.UpdateProvider(ctx, userID, prvID, name, &pconfig.ProviderConfig{PrimaryAgent: &pconfig.AgentConfig{}})\n// after\ncfg := &pconfig.ProviderConfig{PrimaryAgent: &pconfig.AgentConfig{Model: provider.ModelTypeValidModel, Temperature: 0.7}}\nif err := cfg.Validate(); err != nil {\n    return fmt.Errorf(\"fix config before update: %w\", err)\n}\n_, err = ctrl.UpdateProvider(ctx, userID, prvID, name, cfg)","handlingStrategy":"validation","validationCode":"func validProviderConfig(cfg *pconfig.ProviderConfig) bool {\n    if cfg == nil {\n        return false\n    }\n    return cfg.Validate() == nil // run the same validator the controller uses\n}","typeGuard":"func isNonNilConfig(cfg *pconfig.ProviderConfig) bool { return cfg != nil }","tryCatchPattern":"result, err := ctrl.UpdateProvider(ctx, userID, prvID, name, cfg)\nif err != nil {\n    var ve *ValidationError // or strings.Contains(err.Error(), \"invalid provider config\")\n    if strings.Contains(err.Error(), \"invalid provider config\") {\n        return fmt.Errorf(\"rejected config: %w\", err) // surface field-level message to UI\n    }\n    return err\n}","preventionTips":["Run config.Validate() client-side before calling UpdateProvider","Never submit sparse partial configs; merge onto the existing config first","Keep required fields (model, API key) enforced in the UI form","Log the wrapped inner error, which names the failing field"],"tags":["validation","provider-config","go"],"backgroundTag":"provider-config-validation-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}