{"record":{"id":"6146a0fd15fd66d1","repo":"thanos-io/thanos","slug":"parsing-config-yaml-file-6146a0","errorCode":null,"errorMessage":"parsing config YAML file","messagePattern":"parsing config YAML file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/cache/factory.go","lineNumber":46,"sourceCode":"// IndexCacheConfig specifies the index cache config.\ntype IndexCacheConfig struct {\n\tType   IndexCacheProvider `yaml:\"type\"`\n\tConfig any                `yaml:\"config\"`\n\n\t// Available item types are Postings, Series and ExpandedPostings.\n\tEnabledItems []string `yaml:\"enabled_items\"`\n\t// TTL for storing items in remote cache. Not supported for inmemory cache.\n\t// Default value is 24h.\n\tTTL time.Duration `yaml:\"ttl\"`\n}\n\n// NewIndexCache initializes and returns new index cache.\nfunc NewIndexCache(logger log.Logger, confContentYaml []byte, reg prometheus.Registerer) (IndexCache, error) {\n\tlevel.Info(logger).Log(\"msg\", \"loading index cache configuration\")\n\tcacheConfig := &IndexCacheConfig{}\n\tcacheMetrics := NewCommonMetrics(reg)\n\tif err := yaml.UnmarshalStrict(confContentYaml, cacheConfig); err != nil {\n\t\treturn nil, errors.Wrap(err, \"parsing config YAML file\")\n\t}\n\n\tbackendConfig, err := yaml.Marshal(cacheConfig.Config)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"marshal content of cache backend configuration\")\n\t}\n\n\tif cacheConfig.TTL == 0 {\n\t\tcacheConfig.TTL = memcachedDefaultTTL\n\t}\n\n\tvar cache IndexCache\n\tswitch strings.ToUpper(string(cacheConfig.Type)) {\n\tcase string(INMEMORY):\n\t\tcache, err = NewInMemoryIndexCache(logger, cacheMetrics, reg, backendConfig)\n\tcase string(MEMCACHED):\n\t\tvar memcached cacheutil.RemoteCacheClient\n\t\tmemcached, err = cacheutil.NewMemcachedClient(logger, \"index-cache\", backendConfig, reg)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/cache/factory.go#L28-L64","documentation":"NewIndexCache parses the user-supplied YAML configuration for the index cache into IndexCacheConfig using yaml.UnmarshalStrict. This error wraps any YAML syntax error or unknown/invalid field, because strict unmarshaling rejects fields not defined on IndexCacheConfig. It means the configuration content itself could not be decoded into the expected struct.","triggerScenarios":"Calling NewIndexCache(logger, confContentYaml, reg) where confContentYaml contains invalid YAML syntax, or contains fields that do not exist on IndexCacheConfig (e.g. a typo like 'maxsize' instead of 'max_size', or backend-specific keys placed at the top level instead of nested under the backend's config field).","commonSituations":"Misindented cache config blocks in thanos.yml; renaming/retyping config fields after a Thanos version upgrade; pasting an in-memory cache block where a memcached one is expected; leftover deprecated fields like 'host'/'addresses' in the wrong nesting level.","solutions":["Validate the YAML syntax (e.g. with yamllint or a YAML parser) and fix indentation/typos.","Compare the config against the IndexCacheConfig schema for the installed Thanos version and remove unknown fields.","Ensure backend-specific options are nested under the correct field for the configured cache type.","Check the Thanos changelog for renamed index cache config fields between versions."],"exampleFix":"// before\nindex-cache:\n  type: in-memory\n  maxsize: 500000\n// after\nindex-cache:\n  type: in-memory\n  config:\n    max_size: 500000","handlingStrategy":"validation","validationCode":"// Go: validate YAML before calling NewIndexCache\nvar probe map[string]interface{}\nif err := yaml.UnmarshalStrict(confContentYaml, &probe); err != nil {\n\treturn fmt.Errorf(\"invalid index cache config: %w\", err)\n}\nif _, ok := probe[\"type\"]; !ok {\n\treturn errors.New(\"index cache config missing 'type'\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := storecache.NewIndexCache(logger, confYaml, reg); err != nil {\n\tif strings.Contains(err.Error(), \"parsing config YAML file\") {\n\t\tlogger.Error(\"fix index-cache YAML\", \"err\", err)\n\t\tos.Exit(1)\n\t}\n\treturn err\n}","preventionTips":["Lint cache config YAML before deployment (yamllint or a CI schema check).","Keep backend-specific fields nested under 'config'.","Pin and document the Thanos version's config schema next to your manifests."],"tags":["yaml","config","cache"],"backgroundTag":"yaml-parse-error","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}