{"record":{"id":"92c2754db95c4569","repo":"egametang/ET","slug":"unknown-condition-compare-op-op","errorCode":null,"errorMessage":"unknown condition compare op: {op}","messagePattern":"unknown condition compare op: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionCompareHelper.cs","lineNumber":17,"sourceCode":"using System;\n\nnamespace ET\n{\n    public static class ConditionCompareHelper\n    {\n        public static bool Compare(long left, ConditionCompareOp op, long right)\n        {\n            return op switch\n            {\n                ConditionCompareOp.Greater => left > right,\n                ConditionCompareOp.GreaterEqual => left >= right,\n                ConditionCompareOp.Less => left < right,\n                ConditionCompareOp.LessEqual => left <= right,\n                ConditionCompareOp.Equal => left == right,\n                ConditionCompareOp.NotEqual => left != right,\n                _ => throw new Exception($\"unknown condition compare op: {op}\")\n            };\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionCompareHelper.cs#L1-L22","documentation":"Thrown by ConditionCompareHelper.Compare as the default arm of its switch on ConditionCompareOp. The enum only defines Greater..NotEqual (1..6), so reaching the default requires an out-of-range cast value (e.g. (ConditionCompareOp)0 or 7). It is an exhaustiveness guard against uninitialized or corrupt op data.","triggerScenarios":"A BTNumericCompare node whose Op field was never set (default 0, which is not a named enum member), or an op value cast from an arbitrary integer outside 1..6, then passed to ConditionCompareHelper.Compare.","commonSituations":"A numeric compare node created without assigning Op (left at default 0); deserialized data with a missing/invalid op field; casting an unchecked integer into ConditionCompareOp.","solutions":["Ensure every BTNumericCompare.Op is explicitly assigned a valid ConditionCompareOp (1..6) before evaluation.","If the node comes from the parser, confirm the expression always has a comparison operator so Op is set.","Validate the op is defined before calling Compare, e.g. with Enum.IsDefined."],"exampleFix":"// before\nvar nc = new BTNumericCompare { Value = 100 };\n// Op left at default 0 -> throws [51]\nbool r = ConditionCompareHelper.Compare(left, nc.Op, right);\n\n// after\nvar nc = new BTNumericCompare { Op = ConditionCompareOp.Greater, Value = 100 };\nbool r = ConditionCompareHelper.Compare(left, nc.Op, right);","handlingStrategy":"validation","validationCode":"if (!Enum.IsDefined(typeof(ConditionCompareOp), (int)op)) { /* invalid op, handle before Compare */ }\nbool r = ConditionCompareHelper.Compare(left, op, right);","typeGuard":"static bool IsValidOp(ConditionCompareOp op) => Enum.IsDefined(typeof(ConditionCompareOp), op) && (int)op >= 1;","tryCatchPattern":null,"preventionTips":["Always explicitly assign BTNumericCompare.Op when creating nodes.","Validate enum values from deserialized/untrusted sources with Enum.IsDefined.","Treat an unset Op (default 0) as a bug to fix, not a valid state."],"tags":["conditionexpr","enum","switch-exhaustiveness","csharp","unity","runtime"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}