{"record":{"id":"a1045ae3a754a76c","repo":"egametang/ET","slug":"item-config-not-found-configid","errorCode":null,"errorMessage":"item config not found: {configId}","messagePattern":"item config not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.item/Scripts/Hotfix/Server/ItemHelper.cs","lineNumber":39,"sourceCode":"        /// 添加物品到背包\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            {\n                for (int i = 0; i < self.SlotItems.Count; ++i)\n                {\n                    Item item = self.SlotItems[i];\n                    if (item == null)\n                    {\n                        continue;\n                    }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.item/Scripts/Hotfix/Server/ItemHelper.cs#L21-L57","documentation":"Thrown by ItemHelper.AddItem when ItemConfigCategory.Get(configId) returns null. The config category is fetched as a singleton from the Fiber (self.Fiber().GetSingleton<ItemConfigCategory>()); a null result means no ItemConfig row exists for that configId in the loaded config table.","triggerScenarios":"AddItem is called with a configId that is absent from the ItemConfig table — either never defined, removed in a config update, or a wrong/typo id passed by a caller. The check is configId-based, independent of count.","commonSituations":"A new item reward references a configId that was never authored in Luban; a config table rebuild dropped a row; a client message sends a configId that is client-only and not in the server's loaded ItemConfigCategory; a typo or stale constant.","solutions":["Verify the configId exists in the ItemConfig table (Luban source) and that the server actually loaded it.","Validate configId against ItemConfigCategory at the caller/handler boundary and reject unknown ids with an error code instead of letting AddItem throw.","If the id comes from another table (e.g. a reward table), fix that table's reference."],"exampleFix":"// before\nItemHelper.AddItem(comp, configId, count, reason);\n\n// after\nvar cat = comp.Fiber().GetSingleton<ItemConfigCategory>();\nif (cat.Get(configId) == null) { Log.Error($\"unknown item {configId}\"); return; }\nItemHelper.AddItem(comp, configId, count, reason);","handlingStrategy":"validation","validationCode":"var cat = comp.Fiber().GetSingleton<ItemConfigCategory>();\nif (cat.Get(configId) == null)\n{\n    Log.Error($\"reject add: unknown configId {configId}\");\n    return;\n}\nItemHelper.AddItem(comp, configId, count, reason);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate configId against ItemConfigCategory at the handler boundary.","Keep the Luban item table and reward references in sync.","Add a CI check that all configIds referenced in reward tables exist in ItemConfig."],"tags":["item","server","config","add-item","configid"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}