csv: Throw exceptions with context

Feature Request

Q A
New Feature yes
BC Break yes

Proposal

Whenever an exception is thrown it is always a native Exception. This can make it hard to figure out what has gone wrong if the CSV handling is just part of a larger process.

I would like to see native League\Csv\Exception errors being throw to give some context, for example StreamException or HeaderException.

I’m very happy to do this work if there’s a good chance of it being merged.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

I’ve made a list of existing exceptions against what seems to make sense against your suggestions. I don’t obviously see where CannotReadRecord fits so maybe we don’t need that? I do wonder if a StreamException would be useful

Exception location Unchanged SyntaxError CannotReadRecord CannotAddStreamFilter InvalidArgument
AbstractCsv::__clone x
AbstractCsv::chunk x
AbstractCsv::sendHeaders x
AbstractCsv::setDelimiter x
AbstractCsv::setEnclosure x
AbstractCsv::setEscape x
AbstractCsv::addStreamFilter x
ColumnConsistency::__construct x
Reader::setHeader x
Reader::setHeaderOffset x
Reader::computeHeader x
ResultSet::fetchOne x
ResultSet::getColumnIndexByValue ??
ResultSet::getColumnIndexByKey : 197 x
ResultSet::getColumnIndexByKey : 209 ??
Statement::offset x
Statement::limit x
Stream::__clone x
Stream::createFromPath x
Stream::appendFilter x
Stream::filterControl :267 x
Stream::filterControl :271 x
Stream::filterControl :278 x
Stream::rewind x
Stream::seek x
Stream::fseek x
Writer::setFlushThreshold x

Great, I’ll try and get that sorted out later today