{"record":{"id":"a8193cfadaaf7651","repo":"sipeed/picoclaw","slug":"create-chat-by-contact-returned-empty-id-w","errorCode":null,"errorMessage":"create chat by contact returned empty id: %w","messagePattern":"create chat by contact returned empty id: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/channels/deltachat/deltachat.go","lineNumber":649,"sourceCode":"\t\treturn 0, fmt.Errorf(\"get chat by contact: %w\", err)\n\t}\n\tchatID, err := decodeOptionalInt64(raw, \"get chat by contact\")\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif chatID > 0 {\n\t\treturn chatID, nil\n\t}\n\n\traw, err = c.rpc.call(ctx, \"create_chat_by_contact_id\", c.accountID, contactID)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"create chat by contact: %w\", err)\n\t}\n\tif err := json.Unmarshal(raw, &chatID); err != nil {\n\t\treturn 0, fmt.Errorf(\"create chat by contact decode: %w\", err)\n\t}\n\tif chatID <= 0 {\n\t\treturn 0, fmt.Errorf(\"create chat by contact returned empty id: %w\", channels.ErrSendFailed)\n\t}\n\treturn chatID, nil\n}\n\nfunc decodeOptionalInt64(raw json.RawMessage, label string) (int64, error) {\n\tvar id *int64\n\tif err := json.Unmarshal(raw, &id); err != nil {\n\t\treturn 0, fmt.Errorf(\"%s decode: %w\", label, err)\n\t}\n\tif id == nil {\n\t\treturn 0, nil\n\t}\n\treturn *id, nil\n}\n\nfunc (c *DeltaChatChannel) resolveAliasChatID(ctx context.Context, target string) (int64, error) {\n\tfor _, query := range aliasQueries(target) {\n\t\tcontacts, err := c.findMatchingContacts(ctx, query)","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/deltachat/deltachat.go#L631-L667","documentation":"Sanity guard in chatIDForContact: chat creation succeeded and decoded, but the returned chatID is <= 0, which cannot be a valid chat handle. The error wraps the channels.ErrSendFailed sentinel so callers can classify it as a send-path failure; the fault is with the core's response payload, not the request.","triggerScenarios":"Thrown at pkg/channels/deltachat/deltachat.go:649 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Treat as a core-side anomaly: log the raw response for the RPC","Verify the contact id passed in is positive and exists","Retry once — transient core glitches can return 0","Match on errors.Is(err, channels.ErrSendFailed) at the caller for send-flow handling"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","contentChangedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}