{"record":{"id":"5a1cec4382bbc276","repo":"GoogleContainerTools/skaffold","slug":"cannot-marshal-build-artifacts-w","errorCode":null,"errorMessage":"cannot marshal build artifacts: %w","messagePattern":"cannot marshal build artifacts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/helm/util.go","lineNumber":37,"sourceCode":"import (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util\"\n)\n\n// copy of cmd/skaffold/app/flags.BuildOutputs\ntype buildOutputs struct {\n\tBuilds []graph.Artifact `json:\"builds\"`\n}\n\nfunc writeBuildArtifacts(builds []graph.Artifact) (string, func(), error) {\n\tbuildOutput, err := json.Marshal(buildOutputs{builds})\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot marshal build artifacts: %w\", err)\n\t}\n\n\tf, err := os.CreateTemp(\"\", \"builds*.yaml\")\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot create temp file: %w\", err)\n\t}\n\tif _, err := f.Write(buildOutput); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot write to temp file: %w\", err)\n\t}\n\tif err := f.Close(); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"cannot close temp file: %w\", err)\n\t}\n\treturn f.Name(), func() { os.Remove(f.Name()) }, nil\n}\n\n// SanitizeFilePath is used to sanitize filepaths that are provided to the `setFiles` flag\n// helm `setFiles` doesn't work with the unescaped filepath separator (\\) for Windows or if there are unescaped tabs and spaces in the directory names.\n// So we escape all odd count occurrences of `\\` for Windows, and wrap the entire string in quotes if it has spaces.","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/helm/util.go#L19-L55","documentation":"writeBuildArtifacts serializes the list of build artifacts (image names/digests/tags) to JSON for the Helm post-renderer. If json.Marshal of buildOutputs fails, this error is returned. JSON marshaling of plain structs rarely fails, so this usually indicates corrupted/unexpected artifact data.","triggerScenarios":"json.Marshal(buildOutputs{builds}) returns an error — practically only when a graph.Artifact contains a value JSON cannot encode (e.g. a channel, func, or cyclic custom type introduced in a custom build-artifact path).","commonSituations":"Patched or forked Skaffold with custom fields on graph.Artifact; plugin/embedding scenarios passing non-encodable values; otherwise virtually never seen in stock usage.","solutions":["Inspect the wrapped marshal error to identify the offending field","Remove or tag (json:\"-\") non-serializable fields on the artifact struct","Ensure builds come from the standard build pipeline (standard graph.Artifact values)","Rebuild Skaffold from unmodified sources to rule out local patches"],"exampleFix":"// before\ntype Artifact struct {\n    Conn chan string `json:\"conn\"`\n}\n// after\ntype Artifact struct {\n    Conn chan string `json:\"-\"`\n}","handlingStrategy":"try-catch","validationCode":"// Go caller pre-check: builds must be plain JSON-encodable\nif b, err := json.Marshal(builds); err != nil { return fmt.Errorf(\"build artifacts not encodable: %w\", err) }","typeGuard":null,"tryCatchPattern":"skaffoldBinary, env, cleanup, err := helm.PrepareSkaffoldFilter(client, builds, flags)\nif err != nil {\n\tif strings.Contains(err.Error(), \"cannot marshal build artifacts\") {\n\t\tlog.Fatalf(\"non-serializable build artifact data: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Keep graph.Artifact values plain and JSON-serializable","Avoid forking/patching Artifact structs with exotic fields","Tag non-serializable fields json:\"-\" if extending structs","Round-trip builds through json.Marshal in tests to catch regressions"],"tags":["json","marshal","helm","build-artifacts"],"backgroundTag":"json-marshal-failed","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}