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

  1. Re-run the registration command; this is usually a transient network failure.
  2. Check connectivity to the Feishu/Lark accounts host (ping/curl the accounts endpoint behind any proxy).
  3. Disable or bypass corporate MITM proxies/VPNs, or configure HTTPS_PROXY correctly.
  4. 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

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


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/80320912dd796bf4. Report an issue: GitHub.