{"record":{"id":"d4b1ca1299fcc11e","repo":"thanos-io/thanos","slug":"marshal-content-of-cache-backend-configuration","errorCode":null,"errorMessage":"marshal content of cache backend configuration","messagePattern":"marshal content of cache backend configuration","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/queryfrontend/config.go","lineNumber":97,"sourceCode":"}\n\n// CacheProviderConfig is the initial CacheProviderConfig struct holder before parsing it into a specific cache provider.\n// Based on the config type the config is then parsed into a specific cache provider.\ntype CacheProviderConfig struct {\n\tType   ResponseCacheProvider `yaml:\"type\"`\n\tConfig any                   `yaml:\"config\"`\n}\n\n// NewCacheConfig is a parser that converts a Thanos cache config yaml into a cortex cache config struct.\nfunc NewCacheConfig(logger log.Logger, confContentYaml []byte) (*cortexcache.Config, error) {\n\tcacheConfig := &CacheProviderConfig{}\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\tswitch strings.ToUpper(string(cacheConfig.Type)) {\n\tcase string(INMEMORY):\n\t\tvar config InMemoryResponseCacheConfig\n\t\tif err := yaml.Unmarshal(backendConfig, &config); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\treturn &cortexcache.Config{\n\t\t\tEnableFifoCache: true,\n\t\t\tFifocache: cortexcache.FifoCacheConfig{\n\t\t\t\tMaxSizeBytes: config.MaxSize,\n\t\t\t\tMaxSizeItems: config.MaxSizeItems,\n\t\t\t\tValidity:     config.Validity,\n\t\t\t},\n\t\t}, nil\n\tcase string(MEMCACHED):","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/queryfrontend/config.go#L79-L115","documentation":"After extracting the generic cache backend blob, NewCacheConfig re-marshals cacheConfig.Config to YAML for backend-specific unmarshaling. Failure to re-marshal indicates the parsed raw config cannot be serialized, wrapped as 'marshal content of cache backend configuration'.","triggerScenarios":"yaml.Marshal(cacheConfig.Config) fails after a successful strict unmarshal of the provider config — typically a nil or yaml-incompatible value in the Config field.","commonSituations":"Custom or programmatically built cache provider configs holding types yaml.Marshal cannot encode; rarely hit via plain YAML files, more common when constructing config in code or tests.","solutions":["Ensure cacheConfig.Config holds a map or yaml-supported value; check the input YAML 'config' section is a mapping, not a scalar or list.","Verify the Thanos version; older versions had limited Config types — upgrade if using a new backend.","If constructing config in Go, populate Config with a yaml.Marshal-encodable type (map[string]interface{})."],"exampleFix":"# before (config must be a mapping)\ntype: REDIS\nconfig: redis://localhost\n# after\ntype: REDIS\nconfig:\n  endpoints: [localhost:6379]","handlingStrategy":"validation","validationCode":"var p struct {\n    Type   string      `yaml:\"type\"`\n    Config interface{} `yaml:\"config\"`\n}\nif err := yaml.UnmarshalStrict(data, &p); err != nil { return err }\nif _, ok := p.Config.(map[interface{}]interface{}); !ok {\n    return fmt.Errorf(\"cache config section must be a mapping\")\n}","typeGuard":null,"tryCatchPattern":"cfg, err := queryfrontend.NewCacheConfig(logger, yamlBytes)\nif err != nil {\n    if strings.Contains(err.Error(), \"marshal content of cache backend configuration\") {\n        return fmt.Errorf(\"cache backend 'config' section must be a YAML mapping: %w\", err)\n    }\n    return err\n}","preventionTips":["Always write the backend config as a YAML mapping under 'config:'.","Test cache config parsing at startup, not at first request.","Avoid programmatic configs with non-encodable values."],"tags":["config","yaml","query-frontend","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"}