{"record":{"id":"36b1028f4289befb","repo":"egametang/ET","slug":"invalid-item-count","errorCode":null,"errorMessage":"invalid item count","messagePattern":"invalid item count","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.item/Scripts/Hotfix/Server/ItemHelper.cs","lineNumber":32,"sourceCode":"        public static void SetCapacity(ItemComponent self, int capacity)\n        {\n            self.SetCapacity(capacity);\n            NotifyCapacityChange(self);\n        }\n\n        /// <summary>\n        /// 添加物品到背包\n        /// </summary>\n        /// <param name=\"self\">物品组件</param>\n        /// <param name=\"configId\">物品配置ID</param>\n        /// <param name=\"count\">物品数量</param>\n        /// <param name=\"reason\">道具变化原因</param>\n        /// <returns>是否添加成功</returns>\n        public static void AddItem(ItemComponent self, int configId, int count, ItemChangeReason reason)\n        {\n            if (count <= 0)\n            {\n                throw new Exception(\"invalid item count\");\n            }\n\n            ItemConfigCategory itemConfigCategory = self.Fiber().GetSingleton<ItemConfigCategory>();\n            ItemConfig itemConfig = itemConfigCategory.Get(configId);\n            if (itemConfig == null)\n            {\n                throw new Exception($\"item config not found: {configId}\");\n            }\n\n            Log.Debug($\"add item: configId={configId}, count={count}, reason={reason}\");\n\n            int maxStack = itemConfig.MaxStack;\n            int remainCount = count;\n            List<long> updatedItemIds = new();\n\n            // 如果物品可堆叠，先尝试叠加到已有物品\n            if (maxStack > 1)\n            {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.item/Scripts/Hotfix/Server/ItemHelper.cs#L14-L50","documentation":"Thrown by ItemHelper.AddItem when count <= 0. AddItem is the server entry point for granting items; a non-positive count has no valid meaning (you cannot add zero or negative items), so it fails fast. Note the sibling RemoveItem returns false on count <= 0 rather than throwing, so AddItem is the stricter of the two.","triggerScenarios":"Calling ItemHelper.AddItem(self, configId, count, reason) with count <= 0. Common when count comes from a reward table, a loot roll, or a client request that yielded zero.","commonSituations":"A reward/drop formula produces 0 (e.g. Random.Next(min,max) with min==max); a config row with Count=0 used as a placeholder; a client request that was not validated before reaching the server helper.","solutions":["Guard the caller: if (count <= 0) return; before invoking AddItem (mirror RemoveItem's behavior).","Fix the source of count so reward tables/loot rolls never yield <= 0.","Validate client-supplied counts at the handler boundary, not in the core helper."],"exampleFix":"// before\nItemHelper.AddItem(comp, configId, rewardCount, reason); // rewardCount may be 0\n\n// after\nif (rewardCount <= 0) return;\nItemHelper.AddItem(comp, configId, rewardCount, reason);","handlingStrategy":"validation","validationCode":"if (count <= 0) return; // mirror RemoveItem's tolerant behavior\nItemHelper.AddItem(comp, configId, count, reason);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate count at the request handler boundary before reaching the helper.","Ensure reward/loot tables never emit 0.","Treat AddItem as a low-level API that assumes pre-validated input."],"tags":["item","server","add-item","validation"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}