larksuite/cli · error

app registration failed: %s

Error message

app registration failed: %s

What it means

Thrown by RequestAppRegistration at internal/auth/app_registration.go:140 when the begin response either has HTTP status >= 400 or contains an "error" field. The message carries the server's error_description (falling back to error, then 'Unknown error'). This is the library's generic surfaced server-side rejection of the registration initiation.

Source

Thrown at internal/auth/app_registration.go:140

	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)
	}

	// The protocol field is expire_in; accept the legacy expires_in spelling,
	// then normalize to protocol defaults.
	expiresIn := getInt(data, "expire_in", 0)
	if expiresIn <= 0 {
		expiresIn = getInt(data, "expires_in", 0)
	}
	expiresIn = normalizedExpireIn(expiresIn)
	interval := normalizedInterval(getInt(data, "interval", 0))

	deviceCode := getStr(data, "device_code")
	if deviceCode == "" {
		return nil, fmt.Errorf("app registration failed: response missing device_code")
	}

	userCode := getStr(data, "user_code")
	verificationUri := getStr(data, "verification_uri")

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Read the %s text in the message — it is the server's error_description; fix the condition it names.
  2. If rate-limited, wait and retry after the indicated backoff period.
  3. Verify network region: some corporate egress IPs are blocked by the accounts service.
  4. Update the CLI — an outdated protocol request (archetype/auth_method fields) can be rejected by newer servers.
  5. If the message is 'Unknown error', capture logs (logHTTPResponse output) and report the issue with the HTTP status.
Defensive patterns

Strategy: try-catch

Try / catch

resp, err := RequestAppRegistration(ctx, client, brand, errOut)
if err != nil {
    var msg string
    if _, after, ok := strings.Cut(err.Error(), "app registration failed: "); ok {
        msg = after // server-provided error_description; surface to the user
    }
    return fmt.Errorf("registration begin rejected: %s", msg)
}

Prevention

When it happens

Trigger: Server responds 4xx/5xx (rate limit, bad request, unauthorized origin) or returns 200 with an OAuth-style error object such as {"error":"..."} during the 'begin' action of device registration.

Common situations: Server-side rate limiting after repeated registration attempts; blocked region or IP; deprecated/retired registration endpoint returning an error payload; service outage reporting errors in-band.

Related errors


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