{"record":{"id":"0f536f602b8ff1d7","repo":"txthinking/brook","slug":"cache-must-be-with-absolute-path","errorCode":null,"errorMessage":"--cache must be with absolute path","messagePattern":"--cache must be with absolute path","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/brook/main.go","lineNumber":2273,"sourceCode":"\t\t\t\t&cli.StringFlag{\n\t\t\t\t\tName:  \"cache\",\n\t\t\t\t\tUsage: \"Cache file, local absolute file path, default is $HOME/.brook.dhcpserver\",\n\t\t\t\t},\n\t\t\t\t&cli.BoolFlag{\n\t\t\t\t\tName:  \"example\",\n\t\t\t\t\tUsage: \"Show a minimal example of usage\",\n\t\t\t\t},\n\t\t\t},\n\t\t\tAction: func(c *cli.Context) error {\n\t\t\t\tif c.Bool(\"example\") {\n\t\t\t\t\tfmt.Println(\"brook dhcpserver --serverip 192.168.1.10 --start 192.168.1.100 --gateway 192.168.1.1 --dnsserver 192.168.1.1\")\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tif c.String(\"serverip\") == \"\" || c.String(\"start\") == \"\" || c.String(\"gateway\") == \"\" || len(c.StringSlice(\"dnsserver\")) == 0 {\n\t\t\t\t\treturn cli.ShowSubcommandHelp(c)\n\t\t\t\t}\n\t\t\t\tif c.String(\"cache\") != \"\" && !filepath.IsAbs(c.String(\"cache\")) {\n\t\t\t\t\treturn errors.New(\"--cache must be with absolute path\")\n\t\t\t\t}\n\t\t\t\ts, 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\"))\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tg.Add(&runnergroup.Runner{\n\t\t\t\t\tStart: func() error {\n\t\t\t\t\t\treturn s.ListenAndServe()\n\t\t\t\t\t},\n\t\t\t\t\tStop: func() error {\n\t\t\t\t\t\treturn s.Shutdown()\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\treturn nil\n\t\t\t},\n\t\t},\n\t\t&cli.Command{\n\t\t\tName:  \"socks5\",","sourceCodeStart":2255,"sourceCodeEnd":2291,"githubUrl":"https://github.com/txthinking/brook/blob/5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8/cli/brook/main.go#L2255-L2291","documentation":"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.","triggerScenarios":"Running `brook dhcp --interface eth0 --serverip ... --start ... --gateway ... --dnsserver ... --cache leases.json` with a relative cache path at cli/brook/main.go:2273.","commonSituations":"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`.","solutions":["Use an absolute path: --cache /var/lib/brook/dhcp.cache","Create the directory first (e.g. mkdir -p /var/lib/brook) so a follow-up file-open error doesn't occur","Absolutize the path in your launch script with realpath before exec"],"exampleFix":"// before\nbrook dhcp --interface eth0 --cache ./dhcp.json ...\n// after\nbrook dhcp --interface eth0 --cache /var/lib/brook/dhcp.json ...","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default --cache to /var/lib/brook/dhcp.cache when unset"],"tags":["cli","dhcp","path-validation","config"],"backgroundTag":"invalid-argument-value","analyzedSha":"5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8","analyzedAt":"2026-09-06T04:35:00.432Z","contentChangedAt":"2026-09-06T04:35:00.432Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}