PHPOffice/PhpSpreadsheet · error · PhpOffice\PhpSpreadsheet\Exception

Invalid Operation for Errors CF Rule Wizard

Error message

Invalid Operation for Errors CF Rule Wizard

What it means

The Errors wizard exposes its modes through __call against an OPERATORS map with exactly two keys: 'isError' and 'notError'. Any other method name throws - common attempts include hasError(), isErr(), notErrors() or error().

Source

Thrown at src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Errors.php:84

        ) {
            throw new Exception('Conditional is not an Errors CF Rule conditional');
        }

        $wizard = new self($cellRange);
        $wizard->style = $conditional->getStyle();
        $wizard->stopIfTrue = $conditional->getStopIfTrue();
        $wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_CONTAINSERRORS;

        return $wizard;
    }

    /**
     * @param mixed[] $arguments
     */
    public function __call(string $methodName, array $arguments): self
    {
        if (!array_key_exists($methodName, self::OPERATORS)) {
            throw new Exception('Invalid Operation for Errors CF Rule Wizard');
        }

        $this->inverse(self::OPERATORS[$methodName]);

        return $this;
    }
}

View on GitHub (pinned to 65b080eef4)

Solutions

  1. Use only isError() or notError()
  2. Validate dynamic method names against ['isError', 'notError'] before invoking
  3. Catch PhpSpreadsheetException around dynamic calls
  4. Note the inverse mode can also be chosen at construction: newRule(Wizard::ERRORS) vs newRule(Wizard::NOT_ERRORS)

Example fix

// before
$errorsWizard = (new Wizard('A1:E10'))->newRule(Wizard::ERRORS);
$errorsWizard->hasError();   // throws

// after
$errorsWizard->isError();    // or ->notError()
Defensive patterns

Strategy: validation

Validate before calling

$allowed = ['isError', 'notError'];
$method = $config['errorMode'];
if (!in_array($method, $allowed, true)) {
    throw new InvalidArgumentException('Unknown Errors mode: ' . $method);
}
$wizard->$method();

Try / catch

use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;

try {
    $wizard->$method();
} catch (PhpSpreadsheetException $e) {
    throw new InvalidArgumentException('Invalid Errors mode: ' . $method, 0, $e);
}

Prevention

When it happens

Trigger: ->hasError(); ->notErrors() (plural - not a key); ->isErrors(); dynamically built method names that are not exactly isError or notError.

Common situations: Developers guessing symmetric or more descriptive names; IDE autocompletion from the @method docblock not being used; fluent chains assembled from config keys.

Related errors


AI-assisted analysis of PHPOffice/PhpSpreadsheet@65b080eef4 (2026-08-17). Data as JSON: /api/errors/ca2687ff4b4701ff. Report an issue: GitHub.