sipeed/picoclaw · error

create chat by contact

Error message

create chat by contact: %w

What it means

Context wrapper in chatIDForContact around the 'create_chat_by_contact_id' RPC: the lookup succeeded with chatID<=0 (no existing chat), but creating a fresh 1:1 chat for that contact failed at the DeltaChat core. Contact resolution via resolveEmailChatID/resolveAliasChatID aborts here; the contact itself is valid.

Solutions

  1. Inspect the wrapped RPC error (account state, contact validity)
  2. Retry on transient RPC transport failures
  3. Ensure the account is configured and unlocked in DeltaChat core
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at pkg/channels/deltachat/deltachat.go:643 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/95b416347404316d. Report an issue: GitHub.

Appendix: source

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

	return contactID, nil
}

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
	}

View on GitHub (pinned to 49183d7e8d)