{"record":{"id":"084180228e452a0e","repo":"cilium/cilium","slug":"writing-header-w","errorCode":null,"errorMessage":"writing header: %w","messagePattern":"writing header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/dpgen/config.go","lineNumber":61,"sourceCode":"\tspec, err := ebpf.LoadCollectionSpec(args[0])\n\tif err != nil {\n\t\treturn fmt.Errorf(\"loading spec: %w\", err)\n\t}\n\n\ts, err := varsToStruct(spec, configOpts.outName, configOpts.kind, configOpts.typesPkg, configOpts.embeds)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"generating config struct: %w\", err)\n\t}\n\n\tif needUtils {\n\t\tif err := writeUtilFile(\"util_generated.go\", configOpts.goPkg); err != nil {\n\t\t\treturn fmt.Errorf(\"writing util file: %w\", err)\n\t\t}\n\t}\n\n\tvar b bytes.Buffer\n\tif err := writeHeader(&b, configOpts.goPkg, nil); err != nil {\n\t\treturn fmt.Errorf(\"writing header: %w\", err)\n\t}\n\n\tif needExternalTypes {\n\t\tif configOpts.typesPkg == \"\" {\n\t\t\treturn fmt.Errorf(\"external types needed but types package is empty\")\n\t\t}\n\t\tif err := writeImports(&b, []string{configOpts.typesPkg}); err != nil {\n\t\t\treturn fmt.Errorf(\"writing imports: %w\", err)\n\t\t}\n\t}\n\tif _, err := b.WriteString(s); err != nil {\n\t\treturn fmt.Errorf(\"writing struct: %w\", err)\n\t}\n\tif err := os.WriteFile(configOpts.outFile, b.Bytes(), 0644); err != nil {\n\t\treturn fmt.Errorf(\"writing output file: %w\", err)\n\t}\n\n\treturn nil","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/tools/dpgen/config.go#L43-L79","documentation":"Failed while rendering the Go file header (package clause and license comment) into the output buffer via writeHeader. This is part of assembling the generated *_config.go file and indicates an internal template/formatting failure, not a user input problem in most cases.","triggerScenarios":"writeHeader's internal template parsing or execution fails (malformed header template, invalid package name formatting); the bytes.Buffer accepts virtually all writes so real failures are almost always template errors introduced by code changes, or a nil/template misuse regression in tools/dpgen.","commonSituations":"Developers editing the header template in tools/dpgen introduce a template syntax error or pass an invalid goPkg value; rarely hit by end users of the generator.","solutions":["Check the --go-pkg flag value is a valid Go package name (letters/digits/underscore)","Inspect the header template used by writeHeader in tools/dpgen for template syntax errors","Rebuild dpgen (`go build ./tools/dpgen`) after any edits and re-run","If caused by a recent dpgen change, git diff tools/dpgen to find the template regression and fix it"],"exampleFix":"// before\nwriteHeader(&b, \"my-pkg\", nil) // invalid package name\n// after\nwriteHeader(&b, \"mypkg\", nil)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := runConfig(cmd, args); err != nil {\n\tif strings.Contains(err.Error(), \"writing header\") {\n\t\tfmt.Fprintf(os.Stderr, \"dpgen internal header/template failure, check go-pkg flag and rebuild dpgen: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\tfmt.Fprintf(os.Stderr, \"%v\\n\", err)\n\tos.Exit(1)\n}","preventionTips":["Pass a valid Go package name via --go-pkg (identifiers only, no dashes)","Rebuild dpgen after pulling changes so embedded templates match the binary","Run `go vet ./tools/dpgen` after editing header templates","Pin the dpgen build in CI so template and binary versions agree"],"tags":["codegen","go-template","internal"],"backgroundTag":"code-generation-template-failed","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}