Skip to content

'continue' restart doesn't work in cl-csv:read-csv (without :sample) #35

@mjanzen

Description

@mjanzen

I'm running cl-csv-20180831-git (the most recent version I see in Quicklisp) on SBCL 1.5.4. I've found the library to be really useful, and easy to work with; but I've noticed one discrepancy between its documentation and the code.

The cl-csv README.md file says:
in-csv iterate clause and read-csv support continue and filter restarts for errors occurring during read-csv-row

So, I added a handler-bind to my calling code which would catch csv-parse-error and invoke the continue restart. When I tried to read a bad CSV file I found that, as expected, the restart worked correctly for in-csv; while for read-csv-row and do-csv the Lisp debugger reported that no CONTINUE restart was active.

However, the debugger also complained that the restart wasn't active in read-csv, although the documentation says this should have worked. Interestingly, I found that if I call (read-csv stream :sample 999999), then the restart works again.

A quick look at csv.lisp shows that the in-csv macro invokes an internal function called restartable-read-row; and in-csv is used by read-csv-sample. In read-csv, if :sample is specified then read-csv-sample is called; but in the default case, read-csv-with-reader is called instead, and it appears that this does not support the restart.

This explains the behaviour I observed. But is this a bug in the read-csv code, or is it a documentation error - should callers of read-csv not be able to use this restart?

My opinion is that the restart is generally useful and that, as well as being fixed for read-csv, it could arguably be extended to read-csv-row and do-csv too. Am I missing something - is there a reason why it should be restricted to in-csv and read-csv? (Performance considerations, maybe?)

I'd love to be able to submit a pull request with this; but being a newcomer both to cl-csv and to Lisp itself, I'm not sure that would end well. Please have a look and see whether/how the restart can be made available; thanks very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions