{"record":{"id":"7c975dbf6aead43a","repo":"vxcontrol/pentagi","slug":"failed-to-marshal-provider-config-w","errorCode":null,"errorMessage":"failed to marshal provider config: %w","messagePattern":"failed to marshal provider config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/providers/providers.go","lineNumber":797,"sourceCode":"\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\n}\n\nfunc (pc *providerController) DeleteProvider(\n\tctx context.Context,\n\tuserID int64,","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/providers/providers.go#L779-L815","documentation":"After validation, UpdateProvider serializes the config with json.Marshal before persisting it. A failure here is wrapped as \"failed to marshal provider config: %w\". In practice json.Marshal of this struct essentially never fails unless the config contains an unsupported value (e.g. a channel, func, or a custom MarshalJSON returning an error).","triggerScenarios":"json.Marshal(config) returns an error inside UpdateProvider — e.g. a field in pconfig.ProviderConfig carries an unsupported type or a custom MarshalJSON implementation fails.","commonSituations":"A recent code change added a non-serializable field to ProviderConfig; a custom marshaller on a nested type returns an error; corrupted in-memory config built programmatically.","solutions":["Inspect the wrapped inner error to identify which field breaks marshaling","Check for recently added fields on pconfig.ProviderConfig with unsupported types (chan, func, sync primitives)","Add json:\"...\" tags / omit unsupported fields or make them serializable","If a custom MarshalJSON exists on a nested type, fix its error path"],"exampleFix":"// before\nConfig: someField: make(chan int)   // unserializable field in ProviderConfig\n// after\nConfig: someField: nil              // or replace with a serializable representation","handlingStrategy":"try-catch","validationCode":"if _, err := json.Marshal(config); err != nil {\n    return fmt.Errorf(\"config not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"result, err := ctrl.UpdateProvider(ctx, userID, prvID, name, cfg)\nif err != nil && strings.Contains(err.Error(), \"failed to marshal provider config\") {\n    return fmt.Errorf(\"config contains an unsupported field value: %w\", err)\n}","preventionTips":["Keep only JSON-serializable types in ProviderConfig fields","Add json tags to all exported config fields","Pre-marshal the config in tests to catch new unserializable fields early"],"tags":["json","serialization","go"],"backgroundTag":"json-marshal-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}