moodle/moodle · error · BadMethodCallException

Call to undefined method $method

Error message

Call to undefined method $method

What it means

Parser::__call throws BadMethodCallException 'Call to undefined method $method' when an internal parse-state method is invoked that the parser does not implement. This is an internal invariant violation: the parser's state table dispatched to a handler (typically a r_* parsing rule) that does not exist in the installed version — usually caused by a mismatched/corrupted installation or custom parse states.

Solutions

  1. Reinstall the jmespath.php package cleanly (composer update / vendor:publish, delete vendor/ and reinstall)
  2. Clear any cached compiled ASTs from a different library version
  3. Check for local modifications or subclassing of JmesPath\Parser and revert them
  4. If reproducible on a stock install, report the expression as a bug with your library version

Example fix

// before (partial manual copy of src/)
require 'lib/jmespath/src/Parser.php';
// after
composer require mtdowling/jmespath.php
require 'vendor/autoload.php';
Defensive patterns

Strategy: try-catch

Try / catch

try { $result = JmesPath\search($expr, $data); } catch (\BadMethodCallException $e) { if (strpos($e->getMessage(), 'Call to undefined method') === 0) { // library install/version issue: reinstall, clear compiled caches, disable AST cache dir } else { throw $e; } }

Prevention

When it happens

Trigger: The parser's transition table references a rule method absent from Parser.php; typically triggered during compilation (JmesPath\Env::compile / search with AST caching) of an expression whose parse path hits a missing handler, or after partially upgrading/copying library files.

Common situations: Mixed library versions (e.g. a copied src/ folder missing files), custom subclasses overriding parse state handlers, or bytecode/cached ASTs from a different jmespath.php version.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/b2d183f295f97607. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/jmespath/src/Parser.php:517

    public function __call($method, $args)
    {
        $prefix = substr($method, 0, 4);
        if ($prefix == 'nud_' || $prefix == 'led_') {
            $token = substr($method, 4);
            $message = "Unexpected \"$token\" token ($method). Expected one of"
                . " the following tokens: "
                . implode(', ', array_map(function ($i) {
                    return '"' . substr($i, 4) . '"';
                }, array_filter(
                    get_class_methods($this),
                    function ($i) use ($prefix) {
                        return strpos($i, $prefix) === 0;
                    }
                )));
            throw $this->syntax($message);
        }

        throw new \BadMethodCallException("Call to undefined method $method");
    }
}

View on GitHub (pinned to 48ea8c3322)