chenhg5/cc-connect · error
matrix: client http.Client is nil
Error message
matrix: client http.Client is nil
What it means
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.
Source
Thrown at platform/matrix/verification.go:209
return
}
if err := helper.ConfirmSAS(context.Background(), txnID); err != nil {
slog.Error("matrix: confirm SAS failed", "txn_id", txnID, "error", err)
}
}()
}
func (p *Platform) initVerification(ctx context.Context, ch *cryptohelper.CryptoHelper) error {
client := p.getClient()
if client == nil {
return fmt.Errorf("matrix: client not available")
}
// Wrap the client's actual HTTP transport. We must use client.Client directly
// (not p.httpClient) because cryptohelper.Init() may have replaced client.Client
// with a new http.Client instance.
if client.Client == nil {
return fmt.Errorf("matrix: client http.Client is nil")
}
base := client.Client.Transport
if base == nil {
base = http.DefaultTransport
}
client.Client.Transport = &encryptingTransport{base: base, p: p}
slog.Info("matrix: transport wrapped for verification encryption")
callbacks := &verificationCallbacks{platform: p}
helper := verificationhelper.NewVerificationHelper(client, ch.Machine(), nil, callbacks, false, false, true)
if err := helper.Init(ctx); err != nil {
return fmt.Errorf("matrix: init verification: %w", err)
}
p.setVerificationHelper(helper)
slog.Info("matrix: verification helper initialized and event handlers registered")
return nilView on GitHub (pinned to 4000b2338a)
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
Example fix
// before
client, err := mautrix.NewClient(homeserver, userID, token)
// ensure inner HTTP client is set
// after
client, err := mautrix.NewClient(homeserver, userID, token)
if client.Client == nil {
client.Client = &http.Client{Timeout: 60 * time.Second}
} Defensive patterns
Strategy: type-guard
Validate before calling
if c := p.getClient(); c == nil || c.Client == nil {
// abort transport wrapping
} Type guard
func httpTransportReady(c *mautrix.Client) bool { return c != nil && c.Client != nil } Try / catch
if err := p.initVerification(ctx, ch); err != nil {
slog.Error("matrix: verification init failed", "err", err)
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- device ID not available from whoami
- get home dir: %w
- create data dir: %w
- create crypto helper: %w
- init crypto: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/f489a80b5e289787.
Report an issue: GitHub.