{"record":{"id":"73c91aecce61e017","repo":"gohugoio/hugo","slug":"failed-to-decode-filecache-config-w","errorCode":null,"errorMessage":"failed to decode filecache config: %w","messagePattern":"failed to decode filecache config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cache/filecache/filecache_config.go","lineNumber":241,"sourceCode":"\t\tvar ok bool\n\t\tcc, ok := c[k]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"%q is not a valid cache name\", k)\n\t\t}\n\n\t\tdc := &mapstructure.DecoderConfig{\n\t\t\tResult:           &cc,\n\t\t\tDecodeHook:       mapstructure.StringToTimeDurationHookFunc(),\n\t\t\tWeaklyTypedInput: true,\n\t\t}\n\n\t\tdecoder, err := mapstructure.NewDecoder(dc)\n\t\tif err != nil {\n\t\t\treturn c, err\n\t\t}\n\n\t\tif err := decoder.Decode(v); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to decode filecache config: %w\", err)\n\t\t}\n\n\t\tif cc.Dir == \"\" {\n\t\t\treturn c, errors.New(\"must provide cache Dir\")\n\t\t}\n\n\t\tc[k] = cc\n\n\t}\n\n\tfor k, v := range c {\n\t\tdir := filepath.ToSlash(filepath.Clean(v.Dir))\n\t\thadSlash := strings.HasPrefix(dir, \"/\")\n\t\tparts := strings.Split(dir, \"/\")\n\n\t\tfor i, part := range parts {\n\t\t\tif strings.HasPrefix(part, \":\") {\n\t\t\t\tresolved, isResource, err := resolveDirPlaceholder(fs, bcfg, part)","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/cache/filecache/filecache_config.go#L223-L259","documentation":"Each cache entry in the user config is decoded into a FileCacheConfig via mapstructure (filecache_config.go:229-242). If a field value has the wrong type — most commonly maxAge not being a valid duration string — the decode fails and the error is wrapped with this message.","triggerScenarios":"Setting maxAge to an unparseable value like \"abc\" or \"2 days\", or providing dir as a non-string type.","commonSituations":"Invalid duration syntax in maxAge (missing unit, wrong unit); YAML/TOML/JSON type mismatches; copy-paste from docs that use unsupported duration formats.","solutions":["Ensure maxAge uses valid Go duration syntax (e.g. \"24h\", \"30m\", \"300ms\") or -1 for forever or 0 for disabled","Verify dir is a string value","Validate the config file's overall syntax with a linter"],"exampleFix":"# before\n[caches.modules]\nmaxAge = \"2 days\"\n# after\nmaxAge = \"48h\"","handlingStrategy":"validation","validationCode":"// Validate duration strings before they reach the config decoder.\nfunc validateMaxAge(s string) error {\n    if s == \"-1\" || s == \"0\" {\n        return nil\n    }\n    _, err := time.ParseDuration(s)\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Go duration syntax for maxAge (ns, us, ms, s, m, h)","Validate config files with hugo config before building","Avoid non-standard duration formats like '2 days'"],"tags":["cache","filecache","config","mapstructure","duration","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}