{"record":{"id":"69623a1fd65211d9","repo":"egametang/ET","slug":"condition-error-code-out-of-range-token-number","errorCode":null,"errorMessage":"condition error code out of range: {token.Number}","messagePattern":"condition error code out of range: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionExprParser.cs","lineNumber":241,"sourceCode":"            ++this.position;\n            return token.Type switch\n            {\n                ConditionTokenType.Greater => ConditionCompareOp.Greater,\n                ConditionTokenType.GreaterEqual => ConditionCompareOp.GreaterEqual,\n                ConditionTokenType.Less => ConditionCompareOp.Less,\n                ConditionTokenType.LessEqual => ConditionCompareOp.LessEqual,\n                ConditionTokenType.Equal => ConditionCompareOp.Equal,\n                ConditionTokenType.NotEqual => ConditionCompareOp.NotEqual,\n                _ => throw new Exception($\"condition compare op expected, actual: {token.Text}\")\n            };\n        }\n\n        private int ReadErrorCode()\n        {\n            ConditionToken token = this.Expect(ConditionTokenType.Number);\n            if (token.Number < int.MinValue || token.Number > int.MaxValue)\n            {\n                throw new Exception($\"condition error code out of range: {token.Number}\");\n            }\n\n            return (int)token.Number;\n        }\n\n        private void ApplyErrorCode(BTNode node, int errorCode)\n        {\n            if (node is BTNumericCompare numericCompare)\n            {\n                numericCompare.ErrorCode = errorCode;\n                return;\n            }\n\n            if (node is BTCondition condition)\n            {\n                this.SetCompareField(condition, nameof(BTNumericCompare.ErrorCode), errorCode);\n                return;\n            }","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionExprParser.cs#L223-L259","documentation":"Thrown by ConditionExprParser.ReadErrorCode() while parsing the optional `:errorCode` suffix of a condition expression (e.g. `HP > 0:1000`). The Number token read after the colon is wider than int32, and the parser refuses to narrow it when it falls outside [int.MinValue, int.MaxValue]. This protects the downstream BTNumericCompare.ErrorCode field (an int) from silent truncation.","triggerScenarios":"Writing a per-node error code whose literal value exceeds the 32-bit signed integer range after a colon, e.g. `HP > 0:9999999999`, `Unit1.MP < 100:4294967296`, or a negative code below -2147483648. Reached from ParseUnary (line 81) and ParseCompare (line 113) when a Colon token is matched, then via ApplyErrorCode/ReadErrorCode.","commonSituations":"Author copies a full uint/hex error id from a design doc into the Luban/Excel condition cell without realizing the field is signed int32; pasting a 64-bit bit-packed flag value as an error code; negative hex literals that the lexer turns into out-of-range numbers.","solutions":["Clamp the error code literal in the condition cell to the int32 range [-2147483648, 2147483647].","If you genuinely need a wider code, extend ReadErrorCode and BTNumericCompare.ErrorCode to long on both parser and node sides, and regenerate Luban.","Check the design table for the offending row using the reported token.Number value to locate it fast."],"exampleFix":"// before (cell)\nHP > 0:9999999999\n// after\nHP > 0:1000","handlingStrategy":"validation","validationCode":"// before writing the cell / building the parser input\nbool IsValidErrorCode(long code) => code >= int.MinValue && code <= int.MaxValue;\nif (!tokens.Any(t => t.Type == ConditionTokenType.Colon)) return;\n// validate the number token that follows each colon\nlong v = tokenAfterColon.Number;\nif (!IsValidErrorCode(v)) throw new FormatException($\"error code out of int range: {v}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat error codes as signed int32 in design docs and tables.","Add a Luban/Excel pre-export validator that checks every `:code` literal against int32 range.","Unit-test parser against boundary values (int.MinValue, int.MaxValue, +/-1 outside)."],"tags":["csharp","unity","conditionexpr","parser","luban","config-data"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}