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
- Inspect the wrapped json error to identify the failing field or syntax position
- Dump the raw body of the failed response for comparison with the expected envelope
- Verify the response is actually from the app_versions endpoint and not an error page
- 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
- Assert envelope shape with unit-test fixtures mirroring the live API
- Fail fast on non-2xx/non-JSON gateway responses
- Capture raw bodies for debugging production decode errors
- Track Feishu app_versions API changes when upgrading
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
- decode application response: %w
- connection check: decode: %w (body=%s)
- lark-cli stdout was not JSON: {snippet}
- lark-cli returned a non-object JSON payload
- malformed config
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/b3d880b729dfbad1.
Report an issue: GitHub.