{"record":{"id":"b22c851634842247","repo":"larksuite/cli","slug":"marshal-value-for-q-w","errorCode":null,"errorMessage":"marshal value for %q: %w","messagePattern":"marshal value for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/schema/types.go","lineNumber":139,"sourceCode":"\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()\n\tif err != nil {\n\t\treturn err\n\t}\n\tif delim, ok := tok.(json.Delim); !ok || delim != '{' {\n\t\treturn fmt.Errorf(\"expected object, got %v\", tok)\n\t}","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/schema/types.go#L121-L157","documentation":"OrderedMap.MarshalJSON marshals each value (a schema Property) after its key. If json.Marshal of the Property fails, the error is wrapped with the failing key name so the offending entry can be located. This fires when a Property contains a field that cannot be JSON-encoded.","triggerScenarios":"Marshaling an OrderedMap where o.Map[k] is a Property (or contains nested values like custom marshalers, channels, funcs, or cyclic structures handled via MarshalJSON) whose json.Marshal returns an error.","commonSituations":"Custom Property extensions or injected values with broken MarshalJSON implementations; json.Marshaler that returns an error; unsupported types smuggled into interface fields.","solutions":["Read the %q key in the message to find the offending entry in the map","Inspect the wrapped %w cause from json.Marshal for the specific unsupported value","Fix the Property's MarshalJSON implementation or replace the unmarshalable field","Add a unit test marshaling the full OrderedMap to catch this at build time"],"exampleFix":"// before\nfunc (p Property) MarshalJSON() ([]byte, error) { return nil, errors.New(\"unsupported\") }\n// after\nfunc (p Property) MarshalJSON() ([]byte, error) { return json.Marshal(p.fields()) }","handlingStrategy":"try-catch","validationCode":"for k, v := range om.Map {\n\tif _, err := json.Marshal(v); err != nil {\n\t\treturn fmt.Errorf(\"entry %q is not JSON-marshalable: %w\", k, err)\n\t}\n}","typeGuard":"func marshalable(v any) bool {\n\t_, err := json.Marshal(v)\n\treturn err == nil\n}","tryCatchPattern":"data, err := json.Marshal(om)\nif err != nil {\n\tvar keyErr interface{ Error() string }\n\tif strings.Contains(err.Error(), \"marshal value for\") {\n\t\t// key name is quoted between 'for ' and the next ':' — locate and fix that Property\n\t}\n\treturn err\n}","preventionTips":["Never store values with failing MarshalJSON inside Property fields","Test full OrderedMap marshaling in CI","Avoid cyclic references in custom marshalers"],"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"}