{"record":{"id":"436471d09d148dac","repo":"gohugoio/hugo","slug":"invalid-cache-dir-q","errorCode":null,"errorMessage":"invalid cache dir: %q","messagePattern":"invalid cache dir: %q","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cache/filecache/filecache_config.go","lineNumber":133,"sourceCode":"\tMaxAge time.Duration\n\n\t// The directory where files are stored.\n\tDir string\n\n\tfileCacheConfigInternal `json:\"-\"`\n}\n\nfunc (cfg *FileCacheConfig) init() error {\n\tif cfg.DirCompiled == \"\" {\n\t\t// From unit tests. Just check that it does not contain any placeholders.\n\t\tif strings.Contains(cfg.Dir, \":\") {\n\t\t\treturn fmt.Errorf(\"cache dir %q contains unresolved placeholders\", cfg.Dir)\n\t\t}\n\t\tcfg.DirCompiled = cfg.Dir\n\t}\n\t// Sanity check the config.\n\tif len(cfg.DirCompiled) < 5 {\n\t\tpanic(fmt.Sprintf(\"invalid cache dir: %q\", cfg.DirCompiled))\n\t}\n\treturn nil\n}\n\ntype fileCacheConfigInternal struct {\n\tDirCompiled string\n\n\tname          string // The name of this cache, e.g. \"images\", \"modules\" etc.\n\tentryIsDir    bool   // when set, the cache entries represents directories directly below the base dir.\n\tisReadOnly    bool   // when set, the cache is read only and needs to be pruned differently. This is used for the Go modules cache.\n\tIsResourceDir bool   //  resources/_gen will get its own composite filesystem that also checks any theme. TODO(bep) unexport this.\n}\n\n// MarshalJSON marshals FileCacheConfig to JSON with MaxAge as a human-readable string.\nfunc (c FileCacheConfig) MarshalJSON() ([]byte, error) {\n\tvar maxAge any\n\tif c.MaxAge == -1 {\n\t\tmaxAge = -1","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/cache/filecache/filecache_config.go#L115-L151","documentation":"A panic in FileCacheConfig.init() (cache/filecache/filecache_config.go:133) when the compiled cache directory is shorter than 5 characters. This sanity check prevents cache eviction from operating on a root or near-root path, which could delete unrelated files.","triggerScenarios":"A FileCacheConfig whose DirCompiled resolves to an extremely short string such as '/a' or a single letter, typically from a malformed custom Dir or a broken placeholder resolution.","commonSituations":"Hand-rolled cacheDir config pointing at a near-root relative path; corrupted resolution of :cacheDir to an empty/truncated value.","solutions":["Provide a full, meaningful absolute path for the cache directory","Prefer Hugo defaults (:cacheDir/:project) over a hand-rolled short dir","Verify the --cacheDir flag / cacheDir config resolves to a real directory of normal length"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if len(cfg.DirCompiled) < 5 {\n    return fmt.Errorf(\"cache dir %q is too short; use a full absolute path\", cfg.DirCompiled)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use full absolute paths for cache directories","Prefer Hugo defaults over hand-rolled short dirs","Verify --cacheDir resolves to a normal-length directory"],"tags":["cache","config","panic","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}