xai-org/x-algorithm · error · SemanticCheckFailure

The mock for function %s is not defined.

Error message

The mock for function %s is not defined.

What it means

When compiling in test/mock mode, createMock is asked to substitute a target class; if that class is not among the functions registered as mockable (funcs), compilation fails with this error. It guards against mocking unknown targets.

Source

Thrown at botmaker/src/java/com/twitter/botmaker/compiler/CompilerContext.java:471

        return target;
      }

      if (target instanceof ThriftStructOperator) {
        return target;
      }

      String nls = target.getPackageName();
      for (String filter : packages) {
        if (nls.startsWith(filter)) {
          return target;
        }
      }

      if (funcs.contains(className)) {
        return target;
      }

      throw new SemanticCheckFailure(
          String.format("The mock for function %s is not defined.", target.getClassName())
      );
    }
  }
}


View on GitHub (pinned to 24c60942c5)

Solutions

  1. Verify the mock target class name matches the registered mockable function exactly
  2. Register the function in the mock set used by the test CompilerContext
  3. Use the same naming convention (simple vs FQCN) as the registration code
Defensive patterns

Strategy: validation

Validate before calling

if (!funcs.contains(targetClassName)) throw new IllegalArgumentException("No mock registered for " + targetClassName);

Try / catch

catch (SemanticCheckFailure e) { /* verify mock registry contains the exact class name */ }

Prevention

When it happens

Trigger: Compiling an expression with a mock directive naming a function/class that was never registered in the mock function set, or a typo in the class name of the mock target.

Common situations: Writing test mocks for functions that were renamed; the mock registry not being populated (missing setup in test harness); using the fully-qualified vs simple class name inconsistently.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/2dd8824dc04eab14. Report an issue: GitHub.