egametang/ET · error · Exception

unknown condition compare op: {op}

Error message

unknown condition compare op: {op}

What it means

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.

Source

Thrown at Packages/cn.etetet.conditionexpr/Scripts/Model/Share/ConditionCompareHelper.cs:17

using System;

namespace ET
{
    public static class ConditionCompareHelper
    {
        public static bool Compare(long left, ConditionCompareOp op, long right)
        {
            return op switch
            {
                ConditionCompareOp.Greater => left > right,
                ConditionCompareOp.GreaterEqual => left >= right,
                ConditionCompareOp.Less => left < right,
                ConditionCompareOp.LessEqual => left <= right,
                ConditionCompareOp.Equal => left == right,
                ConditionCompareOp.NotEqual => left != right,
                _ => throw new Exception($"unknown condition compare op: {op}")
            };
        }
    }
}

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Ensure every BTNumericCompare.Op is explicitly assigned a valid ConditionCompareOp (1..6) before evaluation.
  2. If the node comes from the parser, confirm the expression always has a comparison operator so Op is set.
  3. Validate the op is defined before calling Compare, e.g. with Enum.IsDefined.

Example fix

// before
var nc = new BTNumericCompare { Value = 100 };
// Op left at default 0 -> throws [51]
bool r = ConditionCompareHelper.Compare(left, nc.Op, right);

// after
var nc = new BTNumericCompare { Op = ConditionCompareOp.Greater, Value = 100 };
bool r = ConditionCompareHelper.Compare(left, nc.Op, right);
Defensive patterns

Strategy: validation

Validate before calling

if (!Enum.IsDefined(typeof(ConditionCompareOp), (int)op)) { /* invalid op, handle before Compare */ }
bool r = ConditionCompareHelper.Compare(left, op, right);

Type guard

static bool IsValidOp(ConditionCompareOp op) => Enum.IsDefined(typeof(ConditionCompareOp), op) && (int)op >= 1;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/92c2754db95c4569. Report an issue: GitHub.