{"record":{"id":"c020d60073bc6a46","repo":"larksuite/cli","slug":"jq-marshal-result-w","errorCode":null,"errorMessage":"jq: marshal result: %w","messagePattern":"jq: marshal result: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/event/consume/jq.go","lineNumber":48,"sourceCode":"// applyJQ returns (nil, nil) when the expression filters out the event (e.g. select).\nfunc applyJQ(code *gojq.Code, data json.RawMessage) (json.RawMessage, error) {\n\tvar input interface{}\n\tif err := json.Unmarshal(data, &input); err != nil {\n\t\treturn nil, fmt.Errorf(\"jq: unmarshal input: %w\", err)\n\t}\n\n\titer := code.Run(input)\n\tv, ok := iter.Next()\n\tif !ok {\n\t\treturn nil, nil\n\t}\n\tif err, isErr := v.(error); isErr {\n\t\treturn nil, fmt.Errorf(\"jq: %w\", err)\n\t}\n\n\tresult, err := json.Marshal(v)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"jq: marshal result: %w\", err)\n\t}\n\treturn json.RawMessage(result), nil\n}\n","sourceCodeStart":30,"sourceCodeEnd":52,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/event/consume/jq.go#L30-L52","documentation":"This error wraps a failure from json.Marshal when applyJQ tries to re-serialize the jq-filtered result value back into JSON before returning it as a json.RawMessage. It only fires after the jq program compiled and executed successfully, but its output value cannot be marshaled — which in practice means the filter produced a value containing non-serializable data (e.g. NaN/Inf numbers or an invalid number produced by the jq evaluation). The 'jq: ' prefix groups all jq-related failures for this consumer.","triggerScenarios":"Calling applyJQ with a compiled jq program whose evaluation result is a Go value that json.Marshal rejects (NaN/Inf floats, unsupported types injected via the jq value bridge); raised via fmt.Errorf('jq: marshal result: %w', err) at internal/event/consume/jq.go:48.","commonSituations":"JQ filter expressions that compute arithmetic producing NaN or division by zero (e.g. '.x / 0'), filters returning huge floats beyond JSON range, or custom value conversions feeding non-marshalable values into the result.","solutions":["Inspect the jq filter expression for arithmetic that can yield NaN/Infinity (division by zero, log of negatives) and guard it, e.g. '.x / (.y // 1)' or 'if .y == 0 then 0 else .x / .y end'.","Print the filter output with a simpler filter (e.g. '.') to see which field is unserializable.","Update or pin the jq evaluation dependency so numeric edge cases produce JSON-safe values.","If the value legitimately cannot be JSON-encoded, return an empty/placeholder RawMessage instead of failing the whole consume step."],"exampleFix":"// before\nfilter := \".count / .total\"\n// if total == 0 the result is +Inf and json.Marshal fails\n\n// after\nfilter := \"if .total == 0 then 0 else .count / .total end\"","handlingStrategy":"validation","validationCode":"// Guard the filter output before returning it as RawMessage\nfunc isJSONSafe(v interface{}) bool {\n\tb, err := json.Marshal(v)\n\treturn err == nil && json.Valid(b)\n}\nif !isJSONSafe(result) {\n\t// substitute a safe default or surface a domain error before applyJQ does\n}","typeGuard":"func safeNumber(f float64) (float64, bool) {\n\tif math.IsNaN(f) || math.IsInf(f, 0) {\n\t\treturn 0, false\n\t}\n\treturn f, true\n}","tryCatchPattern":null,"preventionTips":["Write jq filters that cannot divide by zero; use '// 1' or if/else guards.","Sanity-check new filters with sample event payloads before deploying them to the consumer.","Keep the jq evaluation library pinned and review its changelog for numeric handling fixes.","Unit-test filters with edge-case payloads (zeros, negatives, empty objects)."],"tags":["go","jq","json-marshal"],"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"}