larksuite/cli · error · ErrRegistrationTimedOut

%w: %w

Error message

%w: %w

What it means

registrationContextError in internal/auth maps a done registration context to its terminal error. When the context deadline was exceeded, it returns ErrRegistrationTimedOut wrapped together with context.DeadlineExceeded, so callers can errors.Is-match either sentinel. The message format is the two-%w join of the timeout sentinel and the context error.

Source

Thrown at internal/auth/app_registration.go:55

func normalizedInterval(v int) int {
	if v <= 0 {
		return defaultPollIntervalSeconds
	}
	return v
}

// normalizedExpireIn clamps a non-positive expiry budget to the protocol default.
func normalizedExpireIn(v int) int {
	if v <= 0 {
		return defaultExpireInSeconds
	}
	return v
}

// registrationContextError maps a done context to its terminal reason, keeping the cause.
func registrationContextError(ctx context.Context) error {
	if errors.Is(ctx.Err(), context.DeadlineExceeded) {
		return fmt.Errorf("%w: %w", ErrRegistrationTimedOut, ctx.Err())
	}
	return fmt.Errorf("app registration cancelled: %w", ctx.Err())
}

// AppRegistrationResponse is the response from the app registration begin endpoint.
type AppRegistrationResponse struct {
	DeviceCode              string
	UserCode                string
	VerificationUri         string
	VerificationUriComplete string
	ExpiresIn               int
	Interval                int
}

// AppRegistrationResult is the result of a successful app registration poll.
type AppRegistrationResult struct {
	ClientID     string
	ClientSecret string

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Increase the registration timeout/deadline passed to RegisterAppWithDiscovery
  2. Check network connectivity/latency to the Lark registration endpoint
  3. Detect this case with errors.Is(err, auth.ErrRegistrationTimedOut) and prompt the user to retry
  4. Investigate why registration stalled (device-code polling, upstream 5xx) via logs

Example fix

// before
ctx := context.Background()
// after: generous registration timeout
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
Defensive patterns

Strategy: try-catch

Try / catch

err := auth.RegisterAppWithDiscovery(ctx, ...)
if errors.Is(err, auth.ErrRegistrationTimedOut) {
  // increase timeout or retry; cause is context.DeadlineExceeded
}

Prevention

When it happens

Trigger: RegisterAppWithDiscovery exceeds its configured timeout (context.WithDeadline/WithTimeout fires) before app registration completes, and the code calls registrationContextError with the expired context.

Common situations: Slow network or unreachable registration endpoint causing the device-code flow to outlive the deadline; an overly tight timeout in the caller's context.

Related errors


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