{"record":{"id":"af8da413bc5fdb0b","repo":"apache/beam","slug":"capacity-of-cache-cannot-be-negative-got-v","errorCode":null,"errorMessage":"capacity of cache cannot be negative, got %v","messagePattern":"capacity of cache cannot be negative, got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/util/harnessopts/cache.go","lineNumber":37,"sourceCode":"package harnessopts\n\nimport (\n\t\"fmt\"\n\t\"strconv\"\n\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/hooks\"\n)\n\nconst (\n\tcacheCapacityHook = \"beam:go:hook:sideinputcache:capacity\"\n)\n\n// SideInputCacheCapacity accepts a desired capacity for the side input cache. A non-zero positive\n// integer enables the cache (the capacity of the cache is 0 by default.) Cache use also requires runner\n// support.\nfunc SideInputCacheCapacity(capacity int64) error {\n\tif capacity < 0 {\n\t\treturn fmt.Errorf(\"capacity of cache cannot be negative, got %v\", capacity)\n\t}\n\tcapString := strconv.FormatInt(capacity, 10)\n\t// The hook itself is defined in beam/core/runtime/harness/cache_hooks.go\n\treturn hooks.EnableHook(cacheCapacityHook, capString)\n}\n","sourceCodeStart":19,"sourceCodeEnd":43,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/util/harnessopts/cache.go#L19-L43","documentation":"SideInputCacheCapacity configures the harness side-input cache size via a hook; a negative capacity is invalid since a cache cannot hold negative items. The function returns this error instead of enabling the hook, so callers must pass 0 (default/disabled) or a positive value.","triggerScenarios":"Calling harnessopts.SideInputCacheCapacity with a negative int64, typically from a parsed flag or env variable that used -1 as an 'unset' sentinel or was mis-parsed.","commonSituations":"Using -1 as an 'unset' sentinel value in worker options; config files with negative numbers; arithmetic overflow producing negatives.","solutions":["Pass 0 or a positive capacity to SideInputCacheCapacity","Check the error return and log/propagate it instead of ignoring","Sanitize flags/env values with a lower bound of 0 before calling","Treat 0 as 'disabled' rather than a negative sentinel"],"exampleFix":"// before\ncap := flag.Int64(\"cache\", -1, \"size\")\nharnessopts.SideInputCacheCapacity(*cap) // errors when -1\n// after\ncap := flag.Int64(\"cache\", 0, \"size (0 disables)\")\nif *cap >= 0 {\n    if err := harnessopts.SideInputCacheCapacity(*cap); err != nil { log.Fatal(err) }\n}","handlingStrategy":"validation","validationCode":"if capacity < 0 {\n    return errors.New(\"side input cache capacity must be >= 0\")\n}\nif err := harnessopts.SideInputCacheCapacity(capacity); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 0, not -1, as the 'disabled' value","Check the error return of SideInputCacheCapacity","Validate parsed flags/env before applying worker options"],"tags":["go","apache-beam","harness","cache","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}