{"record":{"id":"40768d946e6de152","repo":"PHPOffice/PhpSpreadsheet","slug":"conditional-is-not-an-errors-cf-rule-conditional","errorCode":null,"errorMessage":"Conditional is not an Errors CF Rule conditional","messagePattern":"Conditional is not an Errors CF Rule conditional","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Errors.php","lineNumber":67,"sourceCode":"\n        $conditional = new Conditional();\n        $conditional->setConditionType(\n            $this->inverse ? Conditional::CONDITION_CONTAINSERRORS : Conditional::CONDITION_NOTCONTAINSERRORS\n        );\n        $conditional->setConditions([$this->expression]);\n        $conditional->setStyle($this->getStyle());\n        $conditional->setStopIfTrue($this->getStopIfTrue());\n\n        return $conditional;\n    }\n\n    public static function fromConditional(Conditional $conditional, string $cellRange = 'A1'): WizardInterface\n    {\n        if (\n            $conditional->getConditionType() !== Conditional::CONDITION_CONTAINSERRORS\n            && $conditional->getConditionType() !== Conditional::CONDITION_NOTCONTAINSERRORS\n        ) {\n            throw new Exception('Conditional is not an Errors CF Rule conditional');\n        }\n\n        $wizard = new self($cellRange);\n        $wizard->style = $conditional->getStyle();\n        $wizard->stopIfTrue = $conditional->getStopIfTrue();\n        $wizard->inverse = $conditional->getConditionType() === Conditional::CONDITION_CONTAINSERRORS;\n\n        return $wizard;\n    }\n\n    /**\n     * @param mixed[] $arguments\n     */\n    public function __call(string $methodName, array $arguments): self\n    {\n        if (!array_key_exists($methodName, self::OPERATORS)) {\n            throw new Exception('Invalid Operation for Errors CF Rule Wizard');\n        }","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Style/ConditionalFormatting/Wizard/Errors.php#L49-L85","documentation":"Wizard\\Errors::fromConditional() rebuilds an Errors wizard from an existing Conditional, but it only accepts the containsErrors and notContainsErrors condition types - the two a Blanks-style inverse wizard can round-trip. Other condition types (cellIs, expression, containsText, ...) are rejected up front.","triggerScenarios":"Calling Errors::fromConditional() on a Conditional built by a CellValue or Expression wizard; passing an ISERROR(A1) rule stored as an expression rather than a true containsErrors rule; mixed-rule loops that force everything through the Errors factory.","commonSituations":"Error-highlighting rules written as expression formulas in imported files; generic rule conversion pipelines; rule editors that assume error checks are always containsErrors type.","solutions":["Check getConditionType() is CONDITION_CONTAINSERRORS or CONDITION_NOTCONTAINSERRORS before calling","Use Wizard::fromConditional() for automatic dispatch","If the rule is an ISERROR() expression, convert it with Wizard\\Expression::fromConditional() instead","Guard batch loops with try/catch"],"exampleFix":"// before\n$wizard = Wizard\\Errors::fromConditional($conditional); // throws unless containsErrors/notContainsErrors\n\n// after\nuse PhpOffice\\PhpSpreadsheet\\Style\\Conditional;\n\nif (in_array($conditional->getConditionType(),\n    [Conditional::CONDITION_CONTAINSERRORS, Conditional::CONDITION_NOTCONTAINSERRORS], true)) {\n    $wizard = Wizard\\Errors::fromConditional($conditional);\n} else {\n    $wizard = Wizard::fromConditional($conditional);\n}","handlingStrategy":"type-guard","validationCode":"use PhpOffice\\PhpSpreadsheet\\Style\\Conditional;\n\nif (in_array($conditional->getConditionType(),\n    [Conditional::CONDITION_CONTAINSERRORS, Conditional::CONDITION_NOTCONTAINSERRORS], true)) {\n    $wizard = Wizard\\Errors::fromConditional($conditional, $cellRange);\n} else {\n    $wizard = Wizard::fromConditional($conditional, $cellRange);\n}","typeGuard":"function isErrorsConditional(Conditional $conditional): bool\n{\n    return in_array(\n        $conditional->getConditionType(),\n        [Conditional::CONDITION_CONTAINSERRORS, Conditional::CONDITION_NOTCONTAINSERRORS],\n        true\n    );\n}","tryCatchPattern":"use PhpOffice\\PhpSpreadsheet\\Exception as PhpSpreadsheetException;\n\ntry {\n    $wizard = Wizard\\Errors::fromConditional($conditional, $cellRange);\n} catch (PhpSpreadsheetException $e) {\n    $wizard = Wizard::fromConditional($conditional, $cellRange);\n}","preventionTips":["Check for the two errors condition types before calling the Errors factory","ISERROR()-based rules stored as formulas are EXPRESSION rules, not errors rules","Use the generic Wizard::fromConditional() when rule origin is unknown","Centralize type dispatch instead of hard-coding one factory"],"tags":["php","phpspreadsheet","conditional-formatting","wizard","errors","type-mismatch"],"backgroundTag":"conditional-rule-type-mismatch","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}