t8y2/dbx · error
encode subscription group config: %w
Error message
encode subscription group config: %w
What it means
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).
Source
Thrown at agents/drivers/rocketmq/consumers.go:626
func fetchSubscriptionGroupConfigs(ctx context.Context, address string) (map[string]*subscriptionGroupConfig, error) {
response, err := invokeRemotingWithClient(ctx, address,
remoting.NewRequest(remoting.GetAllSubscriptionGroupConfig, nil))
if err != nil {
return nil, err
}
var wrapper struct {
SubscriptionGroupTable map[string]*subscriptionGroupConfig `json:"subscriptionGroupTable"`
}
if err := json.Unmarshal(repairRocketMQJSON(response.Body), &wrapper); err != nil {
return nil, fmt.Errorf("decode subscription groups: %w", err)
}
return wrapper.SubscriptionGroupTable, nil
}
func writeSubscriptionGroupConfig(ctx context.Context, address string, config *subscriptionGroupConfig) error {
body, err := json.Marshal(config)
if err != nil {
return fmt.Errorf("encode subscription group config: %w", err)
}
command := remoting.NewRequest(remoting.UpdateAndCreateSubscriptionGroup, nil)
command.Body = body
_, err = invokeRemotingWithClient(ctx, address, command)
return err
}
func ensureMutationCoverage(action, resource string, attempted, succeeded int, lastErr error) error {
if attempted <= 0 {
return fmt.Errorf("no RocketMQ master brokers available to %s %s", action, resource)
}
if succeeded == attempted {
return nil
}
message := fmt.Sprintf("failed to %s %s on all masters: %d of %d succeeded", action, resource, succeeded, attempted)
if lastErr != nil {
return fmt.Errorf("%s: %w", message, lastErr)
}View on GitHub (pinned to c0390bff16)
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
Example fix
// before
if err := json.Marshal(config); err != nil { /* fails on custom type */ }
// after
type subscriptionGroupConfig struct {
GroupName string `json:"groupName"`
ConsumeTimeoutMinutes float64 `json:"consumeTimeoutMin"` // plain field, custom MarshalJSON removed
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := json.Marshal(config); err != nil {
return fmt.Errorf("subscription group config not serializable: %w", err)
} Try / catch
if err := writeSubscriptionGroupConfig(ctx, address, cfg); err != nil {
var encErr *json.UnsupportedTypeError
if errors.As(err, &encErr) {
log.Printf("unsupported field type in config: %v", encErr.Value)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- decode ACL list: %w
- decode consumer status: %w
- decode consumer stats: %w
- decode subscription groups: %w
- invalid params: %w
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/11017f2892e189e0.
Report an issue: GitHub.