txthinking/brook · error

--cache must be with absolute path

Error message

--cache must be with absolute path

What it means

The dhcp subcommand can persist lease state via --cache, and brook requires that path to be absolute so the lease file is found consistently regardless of the daemon's working directory. A relative --cache value is rejected with this error before NewDHCPServer runs.

Source

Thrown at cli/brook/main.go:2273

				&cli.StringFlag{
					Name:  "cache",
					Usage: "Cache file, local absolute file path, default is $HOME/.brook.dhcpserver",
				},
				&cli.BoolFlag{
					Name:  "example",
					Usage: "Show a minimal example of usage",
				},
			},
			Action: func(c *cli.Context) error {
				if c.Bool("example") {
					fmt.Println("brook dhcpserver --serverip 192.168.1.10 --start 192.168.1.100 --gateway 192.168.1.1 --dnsserver 192.168.1.1")
					return nil
				}
				if c.String("serverip") == "" || c.String("start") == "" || c.String("gateway") == "" || len(c.StringSlice("dnsserver")) == 0 {
					return cli.ShowSubcommandHelp(c)
				}
				if c.String("cache") != "" && !filepath.IsAbs(c.String("cache")) {
					return errors.New("--cache must be with absolute path")
				}
				s, err := brook.NewDHCPServer(c.String("interface"), c.String("serverip"), c.String("start"), c.String("netmask"), c.Int("count"), c.String("gateway"), c.StringSlice("dnsserver"), c.String("cache"))
				if err != nil {
					return err
				}
				g.Add(&runnergroup.Runner{
					Start: func() error {
						return s.ListenAndServe()
					},
					Stop: func() error {
						return s.Shutdown()
					},
				})
				return nil
			},
		},
		&cli.Command{
			Name:  "socks5",

View on GitHub (pinned to 5cd13ef3b1)

Solutions

  1. Use an absolute path: --cache /var/lib/brook/dhcp.cache
  2. Create the directory first (e.g. mkdir -p /var/lib/brook) so a follow-up file-open error doesn't occur
  3. Absolutize the path in your launch script with realpath before exec

Example fix

// before
brook dhcp --interface eth0 --cache ./dhcp.json ...
// after
brook dhcp --interface eth0 --cache /var/lib/brook/dhcp.json ...
Defensive patterns

Strategy: fallback

Prevention

When it happens

Trigger: Running `brook dhcp --interface eth0 --serverip ... --start ... --gateway ... --dnsserver ... --cache leases.json` with a relative cache path at cli/brook/main.go:2273.

Common situations: Testing interactively from the config directory then running under systemd from /; mounting a data volume and pointing --cache at a relative mount subpath; typo'd flags like `--cache ./dhcp.cache`.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of txthinking/brook@5cd13ef3b1 (2026-09-06). Data as JSON: /api/errors/0f536f602b8ff1d7. Report an issue: GitHub.