sipeed/picoclaw · error

create chat by contact decode

Error message

create chat by contact decode: %w

What it means

Decode guard in chatIDForContact: the 'create_chat_by_contact_id' RPC returned success, but its raw JSON payload does not unmarshal into int64 — the core returned an unexpected shape (object, string, or null) instead of a bare chat id. The create call itself worked; only the response decoding failed.

Solutions

  1. Log the raw RPC payload to see the actual shape
  2. Update the unmarshal target to the core's current response format (e.g. number inside an envelope)
  3. Handle a null/absent id as a soft failure and retry creation
  4. Check DeltaChat core version compatibility for this RPC method
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/channels/deltachat/deltachat.go:646 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/56b96a0667b2a4fe. Report an issue: GitHub.

Appendix: source

Thrown at pkg/channels/deltachat/deltachat.go:646

func (c *DeltaChatChannel) chatIDForContact(ctx context.Context, contactID int64) (int64, error) {
	raw, err := c.rpc.call(ctx, "get_chat_id_by_contact_id", c.accountID, contactID)
	if err != nil {
		return 0, fmt.Errorf("get chat by contact: %w", err)
	}
	chatID, err := decodeOptionalInt64(raw, "get chat by contact")
	if err != nil {
		return 0, err
	}
	if chatID > 0 {
		return chatID, nil
	}

	raw, err = c.rpc.call(ctx, "create_chat_by_contact_id", c.accountID, contactID)
	if err != nil {
		return 0, fmt.Errorf("create chat by contact: %w", err)
	}
	if err := json.Unmarshal(raw, &chatID); err != nil {
		return 0, fmt.Errorf("create chat by contact decode: %w", err)
	}
	if chatID <= 0 {
		return 0, fmt.Errorf("create chat by contact returned empty id: %w", channels.ErrSendFailed)
	}
	return chatID, nil
}

func decodeOptionalInt64(raw json.RawMessage, label string) (int64, error) {
	var id *int64
	if err := json.Unmarshal(raw, &id); err != nil {
		return 0, fmt.Errorf("%s decode: %w", label, err)
	}
	if id == nil {
		return 0, nil
	}
	return *id, nil
}

View on GitHub (pinned to 49183d7e8d)