larksuite/cli · error
app registration failed: read body: %w
Error message
app registration failed: read body: %w
What it means
Thrown by RequestAppRegistration in internal/auth/app_registration.go:123 when io.ReadAll fails while reading the response body of the device-flow 'begin' POST to the account registration endpoint. The library treats an unreadable body as a failed registration because the device_code payload could not be retrieved. The underlying read error is preserved via %w wrapping.
Source
Thrown at internal/auth/app_registration.go:123
form.Set("auth_method", "client_secret")
form.Set("request_user_info", "open_id tenant_brand")
req, err := http.NewRequestWithContext(ctx, "POST", endpoint, strings.NewReader(form.Encode()))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
logHTTPResponse(resp)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("app registration failed: read body: %w", err)
}
var data map[string]interface{}
if err := json.Unmarshal(body, &data); err != nil {
return nil, fmt.Errorf("app registration failed: HTTP %d – response not JSON", resp.StatusCode)
}
_, hasError := data["error"]
if resp.StatusCode >= 400 || hasError {
msg := getStr(data, "error_description")
if msg == "" {
msg = getStr(data, "error")
}
if msg == "" {
msg = "Unknown error"
}
return nil, fmt.Errorf("app registration failed: %s", msg)
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Re-run the registration command; this is usually a transient network failure.
- Check connectivity to the Feishu/Lark accounts host (ping/curl the accounts endpoint behind any proxy).
- Disable or bypass corporate MITM proxies/VPNs, or configure HTTPS_PROXY correctly.
- If it reproduces consistently, inspect whether a firewall or load balancer truncates responses and retry from a different network.
Defensive patterns
Strategy: retry
Validate before calling
if err := checkHTTPSEndpointReachable(registrationEndpoint); err != nil { return fmt.Errorf("network unreachable before registration: %w", err) } Try / catch
resp, err := RequestAppRegistration(ctx, client, brand, errOut)
if err != nil {
var netErr net.Error
if errors.As(err, &netErr) || strings.Contains(err.Error(), "read body") {
// transient: retry with backoff
}
return err
} Prevention
- Check network/proxy health before starting device registration.
- Avoid flaky networks/VPNs during interactive login flows.
- Set explicit HTTPS_PROXY only when the proxy is known-good.
When it happens
Trigger: The HTTP response body stream from the app-registration begin endpoint breaks mid-read: connection reset by the server or a proxy, truncated chunked transfer-encoding response, TLS connection dropped mid-response, or the 30s begin-request context deadline elapsing while the body is still streaming.
Common situations: Corporate proxies or VPNs killing idle keep-alive connections; flaky mobile/hotel Wi-Fi; server-side load balancers closing connections early; network outages during `lark-cli` first-run app registration.
Related errors
- poll read error: %w
- app registration failed: HTTP %d – response not JSON
- poll network error: %w
- poll parse error: %w
- Device authorization failed: read body: %v
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/80320912dd796bf4.
Report an issue: GitHub.