{"record":{"id":"ad078588fd2be201","repo":"Unity-Technologies/UnityCsReference","slug":"targetcachesize-should-be-0-got-targetcachesi","errorCode":null,"errorMessage":"targetCacheSize should be >= 0, got {targetCacheSize}","messagePattern":"targetCacheSize should be >= 0, got (.+?)","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/ScriptCompilation/BeeDriver/UnityBeeDriver.cs","lineNumber":231,"sourceCode":"            // Note that cacheSize is specified as the total number of used bytes\n            // for all the files in the cache and not as the actual size of occupied\n            // blocks on the disk, which will add some overhead.\n            if (cacheSize < 0)\n                cacheSize = 256 * 1024 * 1024;\n\n            if (cacheDir == null)\n                cacheDir = BeeCacheDir;\n\n            if (runAsync)\n                Task.Run(() => RunCleanBeeCacheInternal(cacheDir, cacheSize));\n            else\n                RunCleanBeeCacheInternal(cacheDir, cacheSize);\n        }\n\n        private static void RunCleanBeeCacheInternal(NPath beeCacheDir, long targetCacheSize)\n        {\n            if (targetCacheSize < 0)\n                throw new ArgumentOutOfRangeException($\"targetCacheSize should be >= 0, got {targetCacheSize}\");\n\n            var sw = new Stopwatch();\n            sw.Start();\n\n            NPath trashDir = beeCacheDir.Combine(\"trash\");\n            trashDir.EnsureDirectoryExists();\n\n            long cacheSize = 0;\n\n            List<CacheEntry> cacheEntries = new List<CacheEntry>();\n            foreach (var subdir in beeCacheDir.Directories())\n            {\n                if (subdir.Equals(trashDir))\n                    continue;\n\n                // Each subdirectory corresponds to a deepcache entry, with the\n                // cache lookup key as the directory name. Files inside those\n                // subdirectories are the blobs referred to by the cache lookup.","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/ScriptCompilation/BeeDriver/UnityBeeDriver.cs#L213-L249","documentation":"ArgumentOutOfRangeException from RunCleanBeeCacheInternal: targetCacheSize must be >= 0. The cache-cleanup routine sizes/evicts entries against this target, so a negative target is invalid.","triggerScenarios":"Calling the Bee cache clean routine with a negative targetCacheSize (cacheSize argument).","commonSituations":"Computing a cache size from a config setting that defaults to -1/unknown, an arithmetic underflow, or misreading a 'disabled' sentinel as a real size.","solutions":["Clamp the cache size to 0 (or a positive value) before calling the clean routine.","Treat -1/unknown config values as 'no limit' rather than passing them through."],"exampleFix":"// before\nRunCleanBeeCacheInternal(cacheDir, cacheSize);\n// after\nlong target = Math.Max(0, cacheSize);\nRunCleanBeeCacheInternal(cacheDir, target);","handlingStrategy":"validation","validationCode":"long target = Math.Max(0, cacheSize);\nRunCleanBeeCacheInternal(cacheDir, target);","typeGuard":"static bool IsValidCacheSize(long size) => size >= 0;","tryCatchPattern":null,"preventionTips":["Clamp computed cache sizes to a minimum of 0 at the config boundary.","Reserve -1 as 'unlimited' and translate it before calling the clean routine."],"tags":["bee","cache","validation","arguments"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}