{"record":{"id":"11017f2892e189e0","repo":"t8y2/dbx","slug":"encode-subscription-group-config-w","errorCode":null,"errorMessage":"encode subscription group config: %w","messagePattern":"encode subscription group config: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rocketmq/consumers.go","lineNumber":626,"sourceCode":"func fetchSubscriptionGroupConfigs(ctx context.Context, address string) (map[string]*subscriptionGroupConfig, error) {\n\tresponse, err := invokeRemotingWithClient(ctx, address,\n\t\tremoting.NewRequest(remoting.GetAllSubscriptionGroupConfig, nil))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar wrapper struct {\n\t\tSubscriptionGroupTable map[string]*subscriptionGroupConfig `json:\"subscriptionGroupTable\"`\n\t}\n\tif err := json.Unmarshal(repairRocketMQJSON(response.Body), &wrapper); err != nil {\n\t\treturn nil, fmt.Errorf(\"decode subscription groups: %w\", err)\n\t}\n\treturn wrapper.SubscriptionGroupTable, nil\n}\n\nfunc writeSubscriptionGroupConfig(ctx context.Context, address string, config *subscriptionGroupConfig) error {\n\tbody, err := json.Marshal(config)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"encode subscription group config: %w\", err)\n\t}\n\tcommand := remoting.NewRequest(remoting.UpdateAndCreateSubscriptionGroup, nil)\n\tcommand.Body = body\n\t_, err = invokeRemotingWithClient(ctx, address, command)\n\treturn err\n}\n\nfunc ensureMutationCoverage(action, resource string, attempted, succeeded int, lastErr error) error {\n\tif attempted <= 0 {\n\t\treturn fmt.Errorf(\"no RocketMQ master brokers available to %s %s\", action, resource)\n\t}\n\tif succeeded == attempted {\n\t\treturn nil\n\t}\n\tmessage := fmt.Sprintf(\"failed to %s %s on all masters: %d of %d succeeded\", action, resource, succeeded, attempted)\n\tif lastErr != nil {\n\t\treturn fmt.Errorf(\"%s: %w\", message, lastErr)\n\t}","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rocketmq/consumers.go#L608-L644","documentation":"writeSubscriptionGroupConfig marshals the subscriptionGroupConfig struct to build the UPDATE_AND_CREATE_SUBSCRIPTION_GROUP command body. If json.Marshal fails it wraps the error as \"encode subscription group config\". This is a client-side serialization problem: the config struct contains a value json cannot encode (e.g. an unsupported type like a channel or func, or an invalid value such as a NaN float).","triggerScenarios":"Calling alterSubscriptionGroupConfig with a subscriptionGroupConfig populated with values that json.Marshal cannot serialize — practically rare since the struct fields are basic types; most likely when a custom field type with a broken MarshalJSON returning an error was added.","commonSituations":"A developer extends subscriptionGroupConfig with a field of a type whose MarshalJSON method errors, or passes a config built programmatically containing an invalid float (NaN/Inf).","solutions":["Inspect the wrapped %w cause to find which field failed to marshal","Check recent additions to subscriptionGroupConfig for custom MarshalJSON implementations or unsupported types","Validate numeric fields for NaN/Inf before calling the write API","Add json tags to any newly added struct fields so they encode as plain JSON","Test the config with json.Marshal(config) in isolation before invoking the broker command"],"exampleFix":"// before\nif err := json.Marshal(config); err != nil { /* fails on custom type */ }\n// after\ntype subscriptionGroupConfig struct {\n    GroupName    string  `json:\"groupName\"`\n    ConsumeTimeoutMinutes float64 `json:\"consumeTimeoutMin\"` // plain field, custom MarshalJSON removed\n}","handlingStrategy":"validation","validationCode":"if _, err := json.Marshal(config); err != nil {\n    return fmt.Errorf(\"subscription group config not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := writeSubscriptionGroupConfig(ctx, address, cfg); err != nil {\n    var encErr *json.UnsupportedTypeError\n    if errors.As(err, &encErr) {\n        log.Printf(\"unsupported field type in config: %v\", encErr.Value)\n    }\n    return err\n}","preventionTips":["Pre-marshaling configs in tests to catch custom-type issues early","Avoid custom MarshalJSON on subscriptionGroupConfig fields","Reject NaN/Inf floats before building configs","Add json tags to every new struct field"],"tags":["json","serialization","rocketmq","config-write"],"backgroundTag":"json-marshal-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}