{"record":{"id":"7d176660dabe909e","repo":"PHPOffice/PhpSpreadsheet","slug":"dgcontainer-is-unexpectedly-null","errorCode":null,"errorMessage":"dgContainer is unexpectedly null","messagePattern":"dgContainer is unexpectedly null","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Shared/Escher.php","lineNumber":56,"sourceCode":"    public function setDggContainer(Escher\\DggContainer $dggContainer): Escher\\DggContainer\n    {\n        return $this->dggContainer = $dggContainer;\n    }\n\n    /**\n     * Get Drawing Container.\n     */\n    public function getDgContainer(): ?Escher\\DgContainer\n    {\n        return $this->dgContainer;\n    }\n\n    /**\n     * Get Drawing Container.\n     */\n    public function getDgContainerOrThrow(): Escher\\DgContainer\n    {\n        return $this->dgContainer ?? throw new SpreadsheetException('dgContainer is unexpectedly null');\n    }\n\n    /**\n     * Set Drawing Container.\n     */\n    public function setDgContainer(Escher\\DgContainer $dgContainer): Escher\\DgContainer\n    {\n        return $this->dgContainer = $dgContainer;\n    }\n}\n","sourceCodeStart":38,"sourceCodeEnd":67,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Shared/Escher.php#L38-L67","documentation":"getDgContainerOrThrow() on Shared\\Escher returns the per-sheet drawing container or throws when unset (src/PhpSpreadsheet/Shared/Escher.php:56). The Xls reader calls it unconditionally while reading worksheet drawings — $escherWorksheet->getDgContainerOrThrow()->getSpgrContainerOrThrow() at src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php:440 — so an Escher stream for a sheet without a valid Dg container triggers it.","triggerScenarios":"Reading an .xls whose sheet-level Escher data is malformed or missing the Dg container while the surrounding records still indicate drawings exist (LoadSpreadsheet.php:440 dereferences both OrThrow accessors in one chain).","commonSituations":"Legacy third-party .xls generators with incomplete Escher output; corrupted drawing records after bad transfers; files edited by multiple old tools.","solutions":["Re-save via Excel/LibreOffice to normalize drawing structures, or convert to .xlsx","If drawings are not needed, convert to CSV or strip images before processing","Catch and quarantine the file in automated pipelines; report the file as malformed","Update PhpSpreadsheet to pick up reader robustness fixes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Cheap gate: skip the Xls reader entirely for non-OLE2 uploads (see error 187 helper)\nif (!looksLikeOle2Spreadsheet($path)) {\n    return reject('Corrupt .xls');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $spreadsheet = $reader->load($path);\n} catch (\\PhpOffice\\PhpSpreadsheet\\Reader\\Exception $e) {\n    if (str_contains($e->getMessage(), 'dgContainer')) {\n        repairPipeline($path); // Excel/LibreOffice re-save, then retry once\n    }\n}","preventionTips":["Normalize third-party .xls output through a re-save step","Log the sheet index that failed to correlate with corrupt drawings","Prefer .xlsx ingest formats where the pipeline allows"],"tags":["xls","escher","drawings","corrupt-file"],"backgroundTag":"unexpected-null-property","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}