{"record":{"id":"78829b11ed9d8f65","repo":"thanos-io/thanos","slug":"marshal-content-of-cache-backend-configuration-78829b","errorCode":null,"errorMessage":"marshal content of cache backend configuration","messagePattern":"marshal content of cache backend configuration","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/cache/factory.go","lineNumber":51,"sourceCode":"\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)\n\t\tif err == nil {\n\t\t\tcache, err = NewRemoteIndexCache(logger, memcached, cacheMetrics, reg, cacheConfig.TTL)\n\t\t}\n\tcase string(REDIS):\n\t\tvar redisCache cacheutil.RemoteCacheClient","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/cache/factory.go#L33-L69","documentation":"After parsing the index cache config, NewIndexCache re-marshals cacheConfig.Config (the opaque backend-specific sub-config) back to YAML to pass to the backend constructor (memcached, redis, etc.). This error is thrown when that in-memory value cannot be marshaled, which is essentially impossible for config-derived data and usually indicates an internal bug or an unsupported value type in Config.","triggerScenarios":"Calling NewIndexCache where the decoded cacheConfig.Config field holds a value that yaml.Marshal cannot serialize (e.g. a custom type with no marshaler containing channel/func values injected programmatically rather than via YAML).","commonSituations":"Programmatic construction of IndexCacheConfig in tests or wrappers stuffing non-serializable values into Config; custom forks adding unsupported field types; virtually never hit from plain YAML files since the value just came from Unmarshal.","solutions":["Inspect what is placed into cacheConfig.Config; ensure only YAML-serializable types are set.","Upgrade or patch Thanos — if triggered by stock YAML input this indicates a bug; file an issue.","As a workaround, pass backend config as plain YAML bytes instead of pre-parsed structures."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"cache, err := storecache.NewIndexCache(logger, confYaml, reg)\nif err != nil && strings.Contains(err.Error(), \"marshal content of cache backend configuration\") {\n\tlogger.Error(\"internal cache-config marshal failure; check programmatic Config values\", \"err\", err)\n}","preventionTips":["Never construct IndexCacheConfig.Config programmatically with non-serializable types.","Feed cache config as raw YAML bytes, the supported input path.","Report occurrences upstream — this wrap point implies a library bug."],"tags":["yaml","config","cache"],"backgroundTag":"json-marshal-failed","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"}