golang/go · error
marshal error %v
Error message
marshal error %v
What it means
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.
Source
Thrown at src/cmd/compile/internal/inline/inlheur/analyze.go:342
func dumpFilePreamble(w io.Writer) {
fmt.Fprintf(w, "// DO NOT EDIT (use 'go test -v -update-expected' instead.)\n")
fmt.Fprintf(w, "// See cmd/compile/internal/inline/inlheur/testdata/props/README.txt\n")
fmt.Fprintf(w, "// for more information on the format of this file.\n")
fmt.Fprintf(w, "// %s\n", preambleDelimiter)
}
// dumpFnPreamble writes out a function-level preamble for a given
// Go function as part of a function properties dump. See the
// README.txt file in testdata/props for more on the format of
// this preamble.
func dumpFnPreamble(w io.Writer, funcInlHeur *fnInlHeur, ecst encodedCallSiteTab, idx, atl uint) error {
fmt.Fprintf(w, "// %s %s %d %d %d\n",
funcInlHeur.file, funcInlHeur.fname, funcInlHeur.line, idx, atl)
// emit props as comments, followed by delimiter
fmt.Fprintf(w, "%s// %s\n", funcInlHeur.props.ToString("// "), comDelimiter)
data, err := json.Marshal(funcInlHeur.props)
if err != nil {
return fmt.Errorf("marshal error %v\n", err)
}
fmt.Fprintf(w, "// %s\n", string(data))
dumpCallSiteComments(w, funcInlHeur.cstab, ecst)
fmt.Fprintf(w, "// %s\n", fnDelimiter)
return nil
}
// sortFnInlHeurSlice sorts a slice of fnInlHeur based on
// the starting line of the function definition, then by name.
func sortFnInlHeurSlice(sl []fnInlHeur) []fnInlHeur {
slices.SortStableFunc(sl, func(a, b fnInlHeur) int {
if a.line != b.line {
return cmp.Compare(a.line, b.line)
}
return strings.Compare(a.fname, b.fname)
})
return sl
}View on GitHub (pinned to b6b368adc5)
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.
Defensive patterns
Strategy: try-catch
Try / catch
// Inside dumpFnPreamble-style helpers, surface marshal errors explicitly.
data, err := json.Marshal(props)
if err != nil {
return fmt.Errorf("marshal props for %s: %w", fname, err)
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- no clauses
- clause %q: expected colon
- clause %q has %d elements, wanted 2
- clause %q: unknown adjustment
- clause %q: malformed value: %v
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/de4028de4e79600e.
Report an issue: GitHub.