larksuite/cli · error

invalid JSON in %s: %w

Error message

invalid JSON in %s: %w

What it means

ReadLarkChannelConfig reads ~/.lark-channel/config.json and unmarshals it into LarkChannelRoot. If the bytes are not syntactically valid JSON (or types don't match the schema, e.g. a string where an object is expected), the error is wrapped with the file path and the underlying json.Unmarshal error so the exact syntax problem is visible.

Source

Thrown at internal/binding/lark_channel.go:56

// chmod-0400 file outside the bridge dir, or an exec script that decrypts a
// local AES-encrypted secret store. Aligns lark-channel with the same secret
// protocol openclaw already uses.
type LarkChannelApp struct {
	ID     string      `json:"id"`
	Secret SecretInput `json:"secret"`
	Tenant string      `json:"tenant"` // "feishu" | "lark"
}

// ReadLarkChannelConfig reads and parses ~/.lark-channel/config.json.
func ReadLarkChannelConfig(path string) (*LarkChannelRoot, error) {
	data, err := vfs.ReadFile(path)
	if err != nil {
		return nil, err // caller formats user-facing message with path context
	}

	var root LarkChannelRoot
	if err := json.Unmarshal(data, &root); err != nil {
		return nil, fmt.Errorf("invalid JSON in %s: %w", path, err)
	}

	return &root, nil
}

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Validate the file with a JSON linter: `jq . <path>` or `python3 -m json.tool <path>`
  2. Fix the reported syntax error at the line/column given in the wrapped error
  3. Restore config.json from a backup or regenerate it via the bridge/CLI setup
  4. Remove comments/BOM and ensure string values are properly quoted

Example fix

// before (config.json)
{"accounts": {"app": {"id": "x", "secret": "y",}}}
// after
{"accounts": {"app": {"id": "x", "secret": "y"}}}
Defensive patterns

Strategy: try-catch

Validate before calling

data, err := os.ReadFile(cfgPath)
if err != nil { return err }
if !json.Valid(data) {
    return fmt.Errorf("%s is not valid JSON", cfgPath)
}

Try / catch

cfg, err := binding.ReadLarkChannelConfig(path)
if err != nil {
    var syntaxErr *json.SyntaxError
    if errors.As(err, &syntaxErr) {
        log.Fatalf("%s line %d: %v", path, syntaxErr.Offset, syntaxErr)
    }
    return err
}

Prevention

When it happens

Trigger: json.Unmarshal returns an error for the file contents: truncated file, trailing commas, comments (not allowed in JSON), BOM prefix, single quotes, or a type mismatch like "accounts": "none".

Common situations: Hand-editing config.json and leaving a stray comma; file corrupted by a crashed writer; secrets templating tool replacing values with invalid placeholders; pasting JSON5/JSONC with comments.

Understand the failure class

Related errors


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