crowdsecurity/crowdsec · error
message for '%s' contains bad data format: %w
Error message
message for '%s' contains bad data format: %w
What it means
DecisionCmd handles 'delete' decisions messages received from PAPI. The message payload must unmarshal into deleteDecisions (a list of decision UUIDs). This error means the JSON payload for the operation type does not match the expected structure.
Source
Thrown at pkg/apiserver/papi_cmd.go:52
Name string `json:"name"`
Id string `json:"id"`
}
func DecisionCmd(ctx context.Context, message *Message, p *Papi, sync bool) error {
switch message.Header.OperationCmd {
case "delete":
data, err := json.Marshal(message.Data)
if err != nil {
return err
}
UUIDs := make([]string, 0)
deleteDecisionMsg := deleteDecisions{
Decisions: make([]string, 0),
}
if err := json.Unmarshal(data, &deleteDecisionMsg); err != nil {
return fmt.Errorf("message for '%s' contains bad data format: %w", message.Header.OperationType, err)
}
UUIDs = append(UUIDs, deleteDecisionMsg.Decisions...)
log.Infof("Decisions UUIDs to remove: %+v", UUIDs)
filter := make(map[string][]string)
filter["uuid"] = UUIDs
_, deletedDecisions, err := p.DBClient.ExpireDecisionsWithFilter(ctx, filter)
if err != nil {
return fmt.Errorf("unable to expire decisions %+v: %w", UUIDs, err)
}
decisions := make([]*models.Decision, 0)
for _, deletedDecision := range deletedDecisions {
log.Infof("Decision from '%s' for '%s' (%s) has been deleted", deletedDecision.Origin, deletedDecision.Value, deletedDecision.Type)
dec := &models.Decision{View on GitHub (pinned to 909b515798)
Solutions
- Verify crowdsec and the PAPI/CAPI source versions match
- Dump the raw message data to inspect the actual payload shape
- Update crowdsec to the latest version to pick up schema changes
- Re-run the pull after confirming server-side health
Defensive patterns
Strategy: try-catch
Validate before calling
var probe map[string]any; if err := json.Unmarshal(data, &probe); err != nil { return fmt.Errorf("payload not JSON") }; if _, ok := probe["decisions"]; !ok { return fmt.Errorf("missing decisions field") } Try / catch
if err := DecisionCmd(ctx, msg, p, false); err != nil { if strings.Contains(err.Error(), "bad data format") { log.Errorf("unparseable PAPI decision message: %v", err) } } Prevention
- Keep sender and receiver crowdsec versions aligned
- Log raw message payloads on failure
- Test message schemas after upgrades
When it happens
Trigger: json.Unmarshal(data, &deleteDecisionMsg) fails on a delete-decisions PAPI message: wrong field types, malformed JSON, or schema drift between CAPI/PAPI sender and this consumer.
Common situations: Incompatible PAPI server version sending a changed payload, a MITM/buggy middlebox altering the message, or custom tooling injecting messages.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- no header in message, skipping
- no source user in header message, skipping
- polling papi message format is not compatible: %+v: %w
- failed to decode response: %w
- unable to expire decisions %+v: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/538a900a89766ebe.
Report an issue: GitHub.