larksuite/cli · error

decode app_versions response: %w

Error message

decode app_versions response: %w

What it means

FetchCurrentPublished in internal/appmeta fetches the app_versions list and unmarshals the response into a typed envelope before selecting the latest published version. This error wraps any json.Unmarshal failure decoding the app_versions response, preserving the cause.

Source

Thrown at internal/appmeta/app_version.go:58

	var envelope struct {
		Data struct {
			Items []struct {
				VersionID   string          `json:"version_id"`
				Version     string          `json:"version"`
				Status      int             `json:"status"`
				PublishTime json.RawMessage `json:"publish_time"`
				EventInfos  []struct {
					EventType string `json:"event_type"`
				} `json:"event_infos"`
				Scopes []struct {
					Scope      string   `json:"scope"`
					TokenTypes []string `json:"token_types"`
				} `json:"scopes"`
			} `json:"items"`
		} `json:"data"`
	}
	if err := json.Unmarshal(raw, &envelope); err != nil {
		return nil, fmt.Errorf("decode app_versions response: %w", err)
	}

	for _, it := range envelope.Data.Items {
		if it.Status != appVersionStatusPublished || !publishTimeSet(it.PublishTime) {
			continue
		}
		v := &AppVersion{
			VersionID: it.VersionID,
			Version:   it.Version,
		}
		for _, e := range it.EventInfos {
			if e.EventType != "" {
				v.EventTypes = append(v.EventTypes, e.EventType)
			}
		}
		for _, s := range it.Scopes {
			if s.Scope != "" && containsString(s.TokenTypes, "tenant") {
				v.TenantScopes = append(v.TenantScopes, s.Scope)

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Inspect the wrapped json error to identify the failing field or syntax position
  2. Dump the raw body of the failed response for comparison with the expected envelope
  3. Verify the response is actually from the app_versions endpoint and not an error page
  4. Update the CLI if the Feishu app_versions API shape changed

Example fix

// before
items, err := meta.FetchCurrentPublished(ctx, raw)
// after (diagnose decode)
if err != nil { log.Printf("decode: %v; body: %s", err, raw) }
Defensive patterns

Strategy: try-catch

Validate before calling

if !json.Valid(raw) { return fmt.Errorf("app_versions response is not valid JSON") }

Try / catch

v, err := meta.FetchCurrentPublished(ctx, raw)
if err != nil {
  var typeErr *json.UnmarshalTypeError
  if errors.As(err, &typeErr) { log.Printf("field %s: %v", typeErr.Field, typeErr) }
  return err
}

Prevention

When it happens

Trigger: The app_versions endpoint returns a body that fails to unmarshal: invalid JSON, or items/scopes fields whose JSON types differ from the envelope (e.g. token_types as object instead of array).

Common situations: Gateway/auth errors returning non-JSON bodies; API schema drift on app_versions; truncated responses over flaky networks.

Related errors


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