{"id":"ce68fdc3193aa8b3","repo":"gohugoio/hugo","slug":"must-not-be-run-from-the-file-system-root","errorCode":null,"errorMessage":"must not be run from the file system root","messagePattern":"must not be run from the file system root","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/mod.go","lineNumber":272,"sourceCode":"\t\t\t\t\t}\n\n\t\t\t\t\tvar lastArg string\n\t\t\t\t\tif len(args) != 0 {\n\t\t\t\t\t\tlastArg = args[len(args)-1]\n\t\t\t\t\t}\n\n\t\t\t\t\tif lastArg == \"./...\" {\n\t\t\t\t\t\targs = args[:len(args)-1]\n\t\t\t\t\t\t// Do a recursive update.\n\t\t\t\t\t\tdirname, err := os.Getwd()\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Sanity chesimplecobra. We do recursive walking and want to avoid\n\t\t\t\t\t\t// accidents.\n\t\t\t\t\t\tif len(dirname) < 5 {\n\t\t\t\t\t\t\treturn errors.New(\"must not be run from the file system root\")\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tfilepath.Walk(dirname, func(path string, info os.FileInfo, err error) error {\n\t\t\t\t\t\t\tif info.IsDir() {\n\t\t\t\t\t\t\t\treturn nil\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif info.Name() == \"go.mod\" {\n\t\t\t\t\t\t\t\t// Found a module.\n\t\t\t\t\t\t\t\tdir := filepath.Dir(path)\n\n\t\t\t\t\t\t\t\tcfg := config.New()\n\t\t\t\t\t\t\t\tcfg.Set(\"workingDir\", dir)\n\t\t\t\t\t\t\t\tconf, err := r.ConfigFromProvider(configKey{counter: r.configVersionID.Add(1)}, flagsToCfg(cd, cfg))\n\t\t\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\t\t\treturn err\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tr.Println(\"Update module in\", conf.configs.Base.WorkingDir)\n\t\t\t\t\t\t\t\tclient := conf.configs.ModulesClient","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/mod.go#L254-L290","documentation":"A safety guard in `hugo mod get ./...` (recursive module update). Before recursively walking the current directory tree looking for `go.mod` files, Hugo checks that the working directory path is at least 5 characters long; a shorter path (e.g. `/`, `C:\\`) means you're at or near the filesystem root, and walking from there would scan the whole disk. Hugo aborts rather than risk that.","triggerScenarios":"Running `hugo mod get -u ./...` (the recursive form, where the last argument is literally `./...`) with the process's working directory at the filesystem root or another path shorter than 5 characters.","commonSituations":"Docker containers or CI jobs whose default WORKDIR is `/`, scripts that fail to `cd` into the project before running the recursive module update, or running from a drive root on Windows.","solutions":["Change into the actual project directory (the one containing your Hugo modules) before running `hugo mod get ./...`.","In Dockerfiles/CI, set WORKDIR to the project path rather than `/`.","If you only need one module updated, drop `./...` and run `hugo mod get -u` inside that module's directory."],"exampleFix":"# before\ncd / && hugo mod get -u ./...\n# after\ncd /srv/mysite && hugo mod get -u ./...","handlingStrategy":"validation","validationCode":"wd, err := os.Getwd()\nif err != nil {\n    return err\n}\nif wd == filepath.VolumeName(wd)+string(os.PathSeparator) || wd == \"/\" {\n    return errors.New(\"run hugo mod from inside the project directory, not /\")\n}","typeGuard":"func isFSRoot(dir string) bool {\n    return dir == \"/\" || dir == filepath.VolumeName(dir)+`\\`\n}","tryCatchPattern":null,"preventionTips":["Always cd into the Hugo project (where hugo.toml/go.mod live) before running hugo mod commands","In scripts and CI, set the working directory explicitly instead of relying on the shell's default","Guard automation with a filesystem-root check before invoking module operations"],"tags":["hugo","hugo-modules","cli","safety-guard"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}