{"record":{"id":"5ddd89a542ea7816","repo":"moodle/moodle","slug":"no-reader-found-for-type-readertype","errorCode":null,"errorMessage":"No reader found for type $readerType","messagePattern":"No reader found for type \\$readerType","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Reader\\Exception","httpStatus":null,"severity":"error","filePath":"public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php","lineNumber":85,"sourceCode":"            }\n\n            // Instantiate writer\n            $className = self::$writers[$writerType];\n        }\n\n        return new $className($spreadsheet);\n    }\n\n    /**\n     * Create IReader.\n     */\n    public static function createReader(string $readerType): IReader\n    {\n        /** @var class-string<IReader> */\n        $className = $readerType;\n        if (!in_array($readerType, self::$readers, true)) {\n            if (!isset(self::$readers[$readerType])) {\n                throw new Reader\\Exception(\"No reader found for type $readerType\");\n            }\n\n            // Instantiate reader\n            $className = self::$readers[$readerType];\n        }\n\n        return new $className();\n    }\n\n    /**\n     * Loads Spreadsheet from file using automatic Reader\\IReader resolution.\n     *\n     * @param string $filename The name of the spreadsheet file\n     * @param int $flags the optional second parameter flags may be used to identify specific elements\n     *                       that should be loaded, but which won't be loaded by default, using these values:\n     *                            IReader::LOAD_WITH_CHARTS - Include any charts that are defined in the loaded file.\n     *                            IReader::READ_DATA_ONLY - Read cell values only, not formatting or merge structure.\n     *                            IReader::IGNORE_EMPTY_CELLS - Don't load empty cells into the model.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/IOFactory.php#L67-L103","documentation":"Thrown by IOFactory::createReader() when the requested reader type name is not a registered reader in IOFactory::$readers. It fires when client code passes an unknown/unregistered type string (e.g. a misspelled format name like 'Xlss' instead of 'Xls', or a custom reader that was never registered via IOFactory::registerReader()). The guard checks in_array($readerType, self::$readers, true), so any type constant not in the built-in list (Xlsx, Xls, Xml, Ods, Slk, Gnumeric, Html, Csv) triggers it.","triggerScenarios":"IOFactory::createReader('XlsX') or a type never registered (registerReader); only registered keys like 'Xlsx', 'Xls', 'Csv', 'Ods', 'Slk', 'Xml', 'Gnumeric' work.","commonSituations":"Case-sensitivity mistakes, custom reader formats not registered, string built dynamically from user input or file extension of an unsupported format.","solutions":["Use an exact registered reader type, e.g. 'Xlsx'","Register custom reader: IOFactory::registerReader('MyType', MyReader::class)","If reading by file, prefer IOfactory::load() / identify() which auto-detects the type"],"exampleFix":"// before\n$reader = IOFactory::createReader($ext); // $ext = 'xlsxx'\n// after\n$reader = IOFactory::createReader('Xlsx');","handlingStrategy":"validation","validationCode":"if (in_array($type, ['Xlsx','Xls','Csv','Ods','Slk','Xml','Gnumeric'], true)) { $reader = IOFactory::createReader($type); }","typeGuard":null,"tryCatchPattern":"try { $reader = IOFactory::createReader($type); } catch (\\PhpOffice\\PhpSpreadsheet\\Reader\\Exception $e) { $reader = null; }","preventionTips":["Use exact registered reader names","Register custom readers before createReader","Prefer IOFactory::identify()/load() to avoid manual type strings"],"tags":["php","phpspreadsheet","reader"],"backgroundTag":"unsupported-enum-value","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}