larksuite/cli · error

BotInfo not available (runtime context not fully initialized

Error message

BotInfo not available (runtime context not fully initialized)

What it means

BotInfo() lazily fetches the bot's identity (/bot/v3/info) at most once per RuntimeContext via sync.OnceValues. This error means the RuntimeContext was constructed without a botInfoFunc, so the library cannot fetch bot identity at all. It signals a programming/wiring problem: the caller is using bot identity in a context that never configured it.

Source

Thrown at shortcuts/common/runner.go:153

	lang, _ := i18n.Parse(string(ctx.Config.Lang))
	return lang
}

// BotInfo holds bot identity metadata fetched lazily from /bot/v3/info.
type BotInfo struct {
	OpenID  string
	AppName string
}

// BotInfo returns the bot's open_id and display name, fetched lazily from /bot/v3/info.
// Unlike UserOpenId() (which reads from config), this requires a network call and may fail.
// Thread-safe via sync.OnceValues; the API is called at most once per RuntimeContext.
func (ctx *RuntimeContext) BotInfo() (*BotInfo, error) {
	if ctx.offline {
		return nil, errs.NewValidationError(errs.SubtypeFailedPrecondition, "BotInfo is unavailable during dry-run")
	}
	if ctx.botInfoFunc == nil {
		return nil, fmt.Errorf("BotInfo not available (runtime context not fully initialized)")
	}
	return ctx.botInfoFunc()
}

// fetchBotInfo calls /bot/v3/info using bot identity and parses the response.
func (ctx *RuntimeContext) fetchBotInfo() (*BotInfo, error) {
	if !ctx.Config.CanBot() {
		return nil, fmt.Errorf("fetch bot info: bot identity is not available in current credential context")
	}
	resp, err := ctx.DoAPIAsBot(&larkcore.ApiReq{
		HttpMethod: http.MethodGet,
		ApiPath:    "/open-apis/bot/v3/info",
	})
	if err != nil {
		return nil, fmt.Errorf("fetch bot info: %w", err)
	}
	if resp.StatusCode >= 400 {
		return nil, fmt.Errorf("fetch bot info: HTTP %d", resp.StatusCode)

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Ensure the RuntimeContext is constructed with a botInfoFunc (the standard runtime setup wires fetchBotInfo); use the normal runtime constructor rather than a minimal/test one for code paths that need bot identity
  2. Check whether the calling shortcut should require bot identity at all; gate on identity availability or surface a typed failed-precondition error to the user instead of relying on the internal error
  3. If in tests, inject a stub botInfoFunc or assert the typed error rather than the plain message

Example fix

// before
info, err := ctx.BotInfo() // panics into 'not fully initialized' in tests
// after
if ctx.BotInfoAvailable() { info, err = ctx.BotInfo() } else { return errs.NewValidationError(errs.SubtypeFailedPrecondition, "bot identity required") }
Defensive patterns

Strategy: validation

Validate before calling

if ctx.FileIO == nil && needsBot { /* check wiring */ }
// Only call when the runtime was built with bot wiring:
info, err := ctx.BotInfo()
if err != nil && strings.Contains(err.Error(), "not fully initialized") { /* wrong runtime constructor */ }

Type guard

func botInfoAvailable(ctx *common.RuntimeContext) bool {
	_, err := ctx.BotInfo()
	return err == nil || !strings.Contains(err.Error(), "not fully initialized")
}

Try / catch

info, err := ctx.BotInfo()
if err != nil {
	if strings.Contains(err.Error(), "not fully initialized") {
		return errs.NewValidationError(errs.SubtypeFailedPrecondition, "bot identity unavailable in this runtime")
	}
	return err
}

Prevention

When it happens

Trigger: Calling BotInfo() (directly or via selfAttendeeId / meetingEventsCurrentIdentity) on a RuntimeContext whose botInfoFunc field is nil — e.g. a context built by a test factory or a minimal runtime path that only wires user (tenant) credentials.

Common situations: Shortcut code calling ctx.BotInfo() under a runtime built without bot wiring; unit tests using cmdutil.TestFactory defaults; dry-run paths that also lack botInfoFunc (though those normally get the dry-run validation error first).

Related errors


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