larksuite/cli · warning

app registration cancelled: %w

Error message

app registration cancelled: %w

What it means

registrationContextError in internal/auth returns this error when the registration context was cancelled for a reason other than deadline expiry (e.g. parent cancellation). It wraps ctx.Err() so the root cause (context.Canceled) remains detectable via errors.Is.

Source

Thrown at internal/auth/app_registration.go:57

		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
	UserInfo     *AppRegUserInfo
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Check errors.Is(err, context.Canceled) to distinguish user-initiated cancellation
  2. Ensure your program does not cancel the shared context prematurely before registration finishes
  3. Handle SIGINT/shutdown gracefully and treat this error as an aborted registration, not a bug
  4. If cancellation is unexpected, audit which parent context is passed to RegisterAppWithDiscovery

Example fix

// before: shared request context cancelled by an unrelated call
ctx := reqCtx
// after: dedicated context for registration
regCtx, regCancel := context.WithCancel(context.Background())
defer regCancel()
Defensive patterns

Strategy: try-catch

Try / catch

err := auth.RegisterAppWithDiscovery(ctx, ...)
if errors.Is(err, context.Canceled) {
  // registration aborted by the caller; treat as user-initiated stop
}

Prevention

When it happens

Trigger: The caller's context passed into RegisterAppWithDiscovery is cancelled while registration is in flight — user abort, parent shutdown, or an explicit cancel() call — and the deadline branch does not match.

Common situations: Ctrl-C / SIGINT during interactive app registration; a parent command being cancelled; the caller cancelling after losing interest without intending a timeout.

Related errors


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