cilium/cilium · error

out cannot be empty

Error message

out cannot be empty

What it means

The dpgen 'config' subcommand requires --out, the path of the Go file to write the generated code into. This PreRunE validation fires when --out is missing or empty, aborting before generation. It guarantees the tool never writes to an unspecified destination.

Source

Thrown at tools/dpgen/main.go:51

		Long: `Generates a configuration struct from a single datapath object.

The struct is generated based on global variables in the object file with a
decl tag matching the provided kind (e.g. "kind:object"). Optionally, additional
structs can be embedded in the generated struct with the --embed flag.

Use with go:generate in a Go source file (e.g. gen.go) to automatically detect
the current package name:

    //go:generate go tool dpgen config --embed Node --kind object --name BPFLXC --out lxc_config.go ../../../bpf/bpf_lxc.o`,
		PreRunE: func(cmd *cobra.Command, args []string) error {
			if configOpts.embed != "" {
				configOpts.embeds = strings.Split(configOpts.embed, ",")
			}
			if configOpts.outName == "" {
				return fmt.Errorf("name cannot be empty")
			}
			if configOpts.outFile == "" {
				return fmt.Errorf("out cannot be empty")
			}
			if configOpts.kind == "" {
				return fmt.Errorf("kind cannot be empty")
			}
			return nil
		},
		RunE: runConfig,
		Args: cobra.ExactArgs(1),
	}

	flags := c.Flags()
	flags.StringVar(&configOpts.outFile, "out", "", "output Go source file for the generated config struct")
	flags.StringVar(&configOpts.outName, "name", "", "name of the generated Go struct in the output file")
	flags.StringVar(&configOpts.kind, "kind", "object", "variables to include based on their decl tags (kind:object, kind:node, ...)")
	flags.StringVar(&configOpts.embed, "embed", "", "comma-separated list of Go structs to embed in the generated struct")
	flags.StringVar(&configOpts.typesPkg, "types", "github.com/cilium/cilium/pkg/datapath/types", "package containing external types managed by 'dpgen type'")

	flags.StringVarP(&configOpts.goPkg, "package", "p", os.Getenv("GOPACKAGE"), "name of the Go package dpgen was invoked for/from (default $GOPACKAGE)")

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Add --out <file>.go to the command line (e.g. --out lxc_config.go).
  2. Check the //go:generate directive for the --out flag and a valid filename.
  3. Run 'dpgen config --help' to confirm flag names.

Example fix

// before
//go:generate go tool dpgen config --embed Node --kind object --name BPFLXC ../../../bpf/bpf_lxc.o
// after
//go:generate go tool dpgen config --embed Node --kind object --name BPFLXC --out lxc_config.go ../../../bpf/bpf_lxc.o
Defensive patterns

Strategy: validation

Validate before calling

if outFile == "" { return fmt.Errorf("--out is required for dpgen config") }; if !strings.HasSuffix(outFile, ".go") { return fmt.Errorf("--out %q should be a .go file", outFile) }

Type guard

func hasOut(args []string) bool { for i, a := range args { if a == "--out" && i+1 < len(args) && args[i+1] != "" { return true } } return false }

Prevention

When it happens

Trigger: Invoking 'dpgen config --embed X --kind object --name Y <obj.o>' without --out, so configOpts.outFile is empty.

Common situations: Omitting --out when scripting codegen; a typo like -output instead of --out; deleting the --out portion of a copied go:generate line.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/2e86c863611949f8. Report an issue: GitHub.