{"record":{"id":"9f02c446f322bf1b","repo":"chenhg5/cc-connect","slug":"cloud-web-nil-reply-context","errorCode":null,"errorMessage":"cloud_web: nil reply context","messagePattern":"cloud_web: nil reply context","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/cloud-web/cloudweb.go","lineNumber":692,"sourceCode":"\t\treturn nil, fmt.Errorf(\"cloud_web: no stored reply context for session %q\", sessionKey)\n\t}\n\treturn replyContext{SessionKey: sessionKey, ReplyCtx: replyCtx}, nil\n}\n\nfunc (p *Platform) sendWire(ctx context.Context, msg map[string]any) error {\n\tif ctx == nil {\n\t\tctx = context.Background()\n\t}\n\treturn p.tp.Send(ctx, msg)\n}\n\nfunc parseReplyCtx(v any) (replyContext, error) {\n\tswitch rc := v.(type) {\n\tcase replyContext:\n\t\treturn rc, nil\n\tcase *replyContext:\n\t\tif rc == nil {\n\t\t\treturn replyContext{}, fmt.Errorf(\"cloud_web: nil reply context\")\n\t\t}\n\t\treturn *rc, nil\n\tdefault:\n\t\treturn replyContext{}, fmt.Errorf(\"cloud_web: invalid reply context type %T\", v)\n\t}\n}\n\nfunc firstNonEmpty(values ...string) string {\n\tfor _, v := range values {\n\t\tif strings.TrimSpace(v) != \"\" {\n\t\t\treturn v\n\t\t}\n\t}\n\treturn \"\"\n}\n","sourceCodeStart":674,"sourceCodeEnd":708,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/cloud-web/cloudweb.go#L674-L708","documentation":"parseReplyCtx normalizes the any-typed reply context passed to send APIs (Reply, SendCard, SendWithButtons, etc.). It accepts replyContext and *replyContext; a typed nil pointer (*replyContext)(nil) is explicitly rejected because dereferencing it would panic. This error signals the caller passed a nil pointer.","triggerScenarios":"Calling Reply/SendCard/SendWithButtons/UpdateMessage/SendPreviewStart/DeletePreviewMessage with a *replyContext variable that is nil — typically an uninitialized handle or the zero result of a failed lookup.","commonSituations":"Storing the result of a lookup that returned (nil, nil) or ignoring the error from a previous call and reusing a nil handle; struct fields of type *replyContext never assigned; a helper returning nil context on some code path.","solutions":["Check the reply context for nil before calling send APIs; skip the send or create a fresh session if nil","Fix the upstream call whose error was ignored, leaving the handle nil","Initialize the *replyContext before use, or pass a value (replyContext) instead of a pointer"],"exampleFix":"// before\nvar rc *cloudweb.ReplyContext\np.Reply(ctx, rc, \"hi\") // panics-avoidance error\n\n// after\nif rc == nil {\n    return fmt.Errorf(\"no reply context available\")\n}\np.Reply(ctx, rc, \"hi\")","handlingStrategy":"type-guard","validationCode":"if rc == nil {\n    return fmt.Errorf(\"cannot send: reply context is nil\")\n}","typeGuard":"if rc, ok := v.(*cloudweb.ReplyContext); !ok || rc == nil { /* invalid/nil */ }","tryCatchPattern":"if err := p.Reply(ctx, rc, msg); err != nil && strings.Contains(err.Error(), \"nil reply context\") {\n    return ErrNoReplyContext\n}","preventionTips":["Always check errors from calls that produce reply contexts before using the handle","Avoid typed-nil returns (return error, not (nil context, nil error))","Initialize context fields at session creation, not lazily"],"tags":["cloud-web","nil","reply-context","type-mismatch"],"backgroundTag":"null-argument","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}