{"record":{"id":"f489a80b5e289787","repo":"chenhg5/cc-connect","slug":"matrix-client-http-client-is-nil","errorCode":null,"errorMessage":"matrix: client http.Client is nil","messagePattern":"matrix: client http\\.Client is nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/matrix/verification.go","lineNumber":209,"sourceCode":"\t\t\treturn\n\t\t}\n\t\tif err := helper.ConfirmSAS(context.Background(), txnID); err != nil {\n\t\t\tslog.Error(\"matrix: confirm SAS failed\", \"txn_id\", txnID, \"error\", err)\n\t\t}\n\t}()\n}\n\nfunc (p *Platform) initVerification(ctx context.Context, ch *cryptohelper.CryptoHelper) error {\n\tclient := p.getClient()\n\tif client == nil {\n\t\treturn fmt.Errorf(\"matrix: client not available\")\n\t}\n\n\t// Wrap the client's actual HTTP transport. We must use client.Client directly\n\t// (not p.httpClient) because cryptohelper.Init() may have replaced client.Client\n\t// with a new http.Client instance.\n\tif client.Client == nil {\n\t\treturn fmt.Errorf(\"matrix: client http.Client is nil\")\n\t}\n\tbase := client.Client.Transport\n\tif base == nil {\n\t\tbase = http.DefaultTransport\n\t}\n\tclient.Client.Transport = &encryptingTransport{base: base, p: p}\n\tslog.Info(\"matrix: transport wrapped for verification encryption\")\n\n\tcallbacks := &verificationCallbacks{platform: p}\n\thelper := verificationhelper.NewVerificationHelper(client, ch.Machine(), nil, callbacks, false, false, true)\n\n\tif err := helper.Init(ctx); err != nil {\n\t\treturn fmt.Errorf(\"matrix: init verification: %w\", err)\n\t}\n\n\tp.setVerificationHelper(helper)\n\tslog.Info(\"matrix: verification helper initialized and event handlers registered\")\n\treturn nil","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/matrix/verification.go#L191-L227","documentation":"initVerification returns \"matrix: client http.Client is nil\" when the underlying mautrix client's HTTP client (client.Client) is nil. The function must wrap that HTTP client's transport with encryptingTransport to encrypt verification traffic, which is impossible without it. This indicates the client object is malformed — normally an internal invariant violation.","triggerScenarios":"initVerification reaches the transport-wrapping step but client.Client == nil, i.e., the mautrix Client was constructed without its inner HTTP client or something reset it to nil.","commonSituations":"A version mismatch between the mautrix-go library and cryptohelper where client construction changed; custom client construction code that omitted the HTTP client; a bug introduced when swapping the client's HTTP client during E2EE setup.","solutions":["Check how the Matrix client is constructed and ensure client.Client (http.Client) is always initialized","Pin/upgrade mautrix-go and cryptohelper to compatible versions","Log client state before initVerification to catch when the HTTP client becomes nil","File/inspect a bug if a library update regressed client initialization"],"exampleFix":"// before\nclient, err := mautrix.NewClient(homeserver, userID, token)\n// ensure inner HTTP client is set\n\n// after\nclient, err := mautrix.NewClient(homeserver, userID, token)\nif client.Client == nil {\n    client.Client = &http.Client{Timeout: 60 * time.Second}\n}","handlingStrategy":"type-guard","validationCode":"if c := p.getClient(); c == nil || c.Client == nil {\n    // abort transport wrapping\n}","typeGuard":"func httpTransportReady(c *mautrix.Client) bool { return c != nil && c.Client != nil }","tryCatchPattern":"if err := p.initVerification(ctx, ch); err != nil {\n    slog.Error(\"matrix: verification init failed\", \"err\", err)\n    return err\n}","preventionTips":["Ensure mautrix clients are constructed with a non-nil inner http.Client","Keep mautrix-go and cryptohelper versions compatible","Add an invariant test that client.Client is non-nil after construction"],"tags":["matrix","e2ee","http-client","internal-state"],"backgroundTag":"internal-invariant-violation","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}