Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

[DX] more helpful exception message in case of invalid value #822

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
9 changes: 8 additions & 1 deletion src/Spout/Writer/ODS/Manager/WorksheetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,14 @@ private function getCellXML(Cell $cell, $styleIndex, $numTimesValueRepeated)
} elseif ($cell->isEmpty()) {
$data .= '/>';
} else {
throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . \gettype($cell->getValue()));
$value = $cell->getValueEvenIfError();

$errorMessage = 'Trying to add a value with an unsupported type: ' . \gettype($value);
if (\is_object($value)) {
$errorMessage .= ' (' . \get_class($value) . ' given)';
}

throw new InvalidArgumentException($errorMessage);
}

return $data;
Expand Down
9 changes: 8 additions & 1 deletion src/Spout/Writer/XLSX/Manager/WorksheetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ private function getCellXML($rowIndexOneBased, $columnIndexZeroBased, Cell $cell
$cellXML = '';
}
} else {
throw new InvalidArgumentException('Trying to add a value with an unsupported type: ' . \gettype($cell->getValue()));
$value = $cell->getValueEvenIfError();

$errorMessage = 'Trying to add a value with an unsupported type: ' . \gettype($value);
if (\is_object($value)) {
$errorMessage .= ' (' . \get_class($value) . ' given)';
}

throw new InvalidArgumentException($errorMessage);
}

return $cellXML;
Expand Down