{"record":{"id":"5cf6d2e1e2885db1","repo":"larksuite/cli","slug":"marshal-key-q-w","errorCode":null,"errorMessage":"marshal key %q: %w","messagePattern":"marshal key %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"internal/schema/types.go","lineNumber":133,"sourceCode":"\t\treturn []byte(\"{}\"), nil\n\t}\n\tkeys := o.Order\n\tif len(keys) == 0 {\n\t\tkeys = make([]string, 0, len(o.Map))\n\t\tfor k := range o.Map {\n\t\t\tkeys = append(keys, k)\n\t\t}\n\t\tsort.Strings(keys)\n\t}\n\tvar buf bytes.Buffer\n\tbuf.WriteByte('{')\n\tfor i, k := range keys {\n\t\tif i > 0 {\n\t\t\tbuf.WriteByte(',')\n\t\t}\n\t\tkeyJSON, err := json.Marshal(k)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"marshal key %q: %w\", k, err)\n\t\t}\n\t\tbuf.Write(keyJSON)\n\t\tbuf.WriteByte(':')\n\t\tvalJSON, err := json.Marshal(o.Map[k])\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"marshal value for %q: %w\", k, err)\n\t\t}\n\t\tbuf.Write(valJSON)\n\t}\n\tbuf.WriteByte('}')\n\treturn buf.Bytes(), nil\n}\n\n// UnmarshalJSON parses an object preserving key order via json.Decoder.Token().\n// Used for round-tripping in tests (and future golden update flows).\nfunc (o *OrderedProps) UnmarshalJSON(data []byte) error {\n\tdec := json.NewDecoder(bytes.NewReader(data))\n\ttok, err := dec.Token()","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/schema/types.go#L115-L151","documentation":"OrderedMap.MarshalJSON serializes the map while preserving insertion order by marshaling each key separately. This error wraps a failure from json.Marshal on an individual key. In practice keys are Go strings, which always marshal successfully, so this is a defensive guard that should virtually never fire.","triggerScenarios":"Calling json.Marshal (or any encoding that invokes MarshalJSON) on an internal/schema OrderedMap whose key cannot be JSON-encoded. With the current string-typed keys this is unreachable; it would only fire if the key type changed to a non-JSON-serializable type (e.g. chan, func, or a type with a failing MarshalJSON).","commonSituations":"Developers encounter this only via the wrapped cause in a larger marshal failure chain, typically while debugging custom schema property maps after modifying the OrderedMap key type.","solutions":["Inspect the wrapped %w cause to identify the unmarshalable key value","Confirm keys are plain strings; strings are always JSON-marshalable","If you changed the key type, add a MarshalJSON method to the key type or convert keys to string before insertion"],"exampleFix":"// before (custom key type that fails to marshal)\ntype Key struct{ ID chan int }\n// after\ntype Key struct{ ID string }\nfunc (k Key) MarshalJSON() ([]byte, error) { return json.Marshal(k.ID) }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"data, err := json.Marshal(om)\nif err != nil {\n\tvar mErr *fmt.wrapError\n\tif errors.As(err, &mErr) && strings.Contains(err.Error(), \"marshal key\") {\n\t\t// fix key type in OrderedMap\n\t}\n\treturn err\n}","preventionTips":["Keep OrderedMap keys as plain strings","Add marshal round-trip tests for OrderedMap","If changing key type, give it a working MarshalJSON"],"tags":["json","serialization","schema"],"backgroundTag":"json-marshal-failed","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}