spout icon indicating copy to clipboard operation
spout copied to clipboard

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

Open andrew-demb opened this issue 4 years ago • 3 comments

It is should provide a more helpful message for developer in exception, when in cell value provided an object.

Example:

Exception:

Uncaught PHP Exception Box\\Spout\\Common\\Exception\\InvalidArgumentException: \"Trying to add a value with an unsupported type: NULL\" at /project/vendor/box/spout/src/Spout/Writer/XLSX/Manager/WorksheetManager.php line 256

I may assume, that in my code somewhere used null and passed to spout, but the real reason was - object was provided for cell value, and this lead to described above exception.

This PR will improve an error message and provide a better DX.

andrew-demb avatar Jun 22 '21 13:06 andrew-demb

Hi! I believe that your interpretation may not be correct. gettype($object) should return "object" and not "NULL" like you describe. Only gettype(null) returns "NULL". So here, it seems like a NULL value is passed in.

adrilo avatar Jun 22 '21 15:06 adrilo

Yes, it was output NULL because $cell->getValue() returned null, but this method return null, because resolved cell type was an error

So PR propose change $cell->getValue() to $cell->getValueEvenIfError() AND explain object class name, when it is contained in value.

andrew-demb avatar Jun 22 '21 15:06 andrew-demb

Probably Travis CI check should be retried because PR check status was not changed to finished status.

andrew-demb avatar Jun 29 '21 15:06 andrew-demb