{"record":{"id":"de4028de4e79600e","repo":"golang/go","slug":"marshal-error-v","errorCode":null,"errorMessage":"marshal error %v\n","messagePattern":"marshal error (.+?)\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/compile/internal/inline/inlheur/analyze.go","lineNumber":342,"sourceCode":"func dumpFilePreamble(w io.Writer) {\n\tfmt.Fprintf(w, \"// DO NOT EDIT (use 'go test -v -update-expected' instead.)\\n\")\n\tfmt.Fprintf(w, \"// See cmd/compile/internal/inline/inlheur/testdata/props/README.txt\\n\")\n\tfmt.Fprintf(w, \"// for more information on the format of this file.\\n\")\n\tfmt.Fprintf(w, \"// %s\\n\", preambleDelimiter)\n}\n\n// dumpFnPreamble writes out a function-level preamble for a given\n// Go function as part of a function properties dump. See the\n// README.txt file in testdata/props for more on the format of\n// this preamble.\nfunc dumpFnPreamble(w io.Writer, funcInlHeur *fnInlHeur, ecst encodedCallSiteTab, idx, atl uint) error {\n\tfmt.Fprintf(w, \"// %s %s %d %d %d\\n\",\n\t\tfuncInlHeur.file, funcInlHeur.fname, funcInlHeur.line, idx, atl)\n\t// emit props as comments, followed by delimiter\n\tfmt.Fprintf(w, \"%s// %s\\n\", funcInlHeur.props.ToString(\"// \"), comDelimiter)\n\tdata, err := json.Marshal(funcInlHeur.props)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"marshal error %v\\n\", err)\n\t}\n\tfmt.Fprintf(w, \"// %s\\n\", string(data))\n\tdumpCallSiteComments(w, funcInlHeur.cstab, ecst)\n\tfmt.Fprintf(w, \"// %s\\n\", fnDelimiter)\n\treturn nil\n}\n\n// sortFnInlHeurSlice sorts a slice of fnInlHeur based on\n// the starting line of the function definition, then by name.\nfunc sortFnInlHeurSlice(sl []fnInlHeur) []fnInlHeur {\n\tslices.SortStableFunc(sl, func(a, b fnInlHeur) int {\n\t\tif a.line != b.line {\n\t\t\treturn cmp.Compare(a.line, b.line)\n\t\t}\n\t\treturn strings.Compare(a.fname, b.fname)\n\t})\n\treturn sl\n}","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/compile/internal/inline/inlheur/analyze.go#L324-L360","documentation":"Returned by dumpFnPreamble in the inline-heuristics analyzer when json.Marshal of a FunctionProps value fails while writing the function-properties dump (the // props comments used by testdata/props golden files). Because FunctionProps are produced by the compiler itself, a marshal failure indicates a programming bug in the props types, not a user input problem.","triggerScenarios":"Compiling with GOEXPR=inlheurdump or the internal -d flag that enables function-properties dumps; json.Marshal(funcInlHeur.props) returns an error (e.g. an unencodable channel/func field slipped into the props struct).","commonSituations":"Internal Go compiler development: editing inlheur props structs and forgetting json tags / adding a non-marshalable field; running the inlheur testdata suite against a half-finished change.","solutions":["Inspect the FunctionProps/ParamProps/ResultProp types for non-JSON-encodable fields and add json.Marshaler or json tags.","Check the wrapped error (the %v) for the exact marshal failure type.","Revert recent inlheur struct changes and re-run the dump to bisect which field broke serialization."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Inside dumpFnPreamble-style helpers, surface marshal errors explicitly.\ndata, err := json.Marshal(props)\nif err != nil {\n    return fmt.Errorf(\"marshal props for %s: %w\", fname, err)\n}","preventionTips":["Keep FunctionProps and related structs fully JSON-encodable (no chan/func without a Marshaler).","Add unit tests that json.Marshal every props type.","Run the inlheur testdata suite before committing compiler changes."],"tags":["go-compiler","inline-heuristics","json-marshal","internal"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}