DEV Community

Burdette Lamar
Burdette Lamar

Posted on

Questions for CSV Users

A while back I learned from the good folks over at ruby/csv that for performance reasons, CSV methods do not type-check their arguments. Therefore an invalid argument will eventually cause an error somewhere downstream. The original cause of the error may or may not be obvious.


[Added, for clarity.]

For example, in the method call CSV.new(s), s must be String-convertible or an IO stream open for reading, but this is not checked when the call is executed. An invalid s is discovered only later, when there's an attempt to read from it.


I'm considering creating a gem (possibly called csv_debug) such that:

  • require 'csv_debug' would transparently perform type checking, raising an exception on violation.
  • Changing to require 'csv' would return things to normal.

For example, CSV.new(data, **options) takes 24 options, most of which are not used immediately. The gem would type-check each option (as well as data) as soon as the method is called.

Using the gem would allow an application that uses CSV to have type checking in development, but no type checking in production.

Questions:

  • Would this gem be useful?
  • Is there a better name for the gem? (There's already a gem called csv_safe that guards against dangerous CSV data.)

Top comments (2)

Collapse
 
ecguo profile image
Eric-Guo

How about call it csv_guard?

Collapse
 
kspurgin profile image
Kristina Spurgin

Heavy CSV user here. The most common/annoying things I run into are not type-related. But my situation is that almost all the CSVs are created in-house using the same CSV 'dialect' so we honestly need to use very few of the available CSV options. I'm not saying it wouldn't be useful, given some other CSV use scenario. It seems like a nice tool to have available, but I'm not clear where I'd personally need to use it at the moment.