
10 Ways Ruby's CSV.read Can Silently Corrupt or Lose Your Data
When having to parse CSV files, many developers go straight to the Ruby CSV library — but it comes at the cost of writing boilerplate post-processing, and there are some dangerous pitfalls you might not be aware of. Ruby's built-in CSV library is for many the go-to — it ships with Ruby and requires no dependencies. But it has failure modes that produce no exception, no warning, and no indication that anything went wrong . Your import runs, your tests pass, and your data is quietly wrong. This article documents ten reproducible ways CSV.read (and CSV.table ) can silently corrupt or lose data, with examples you can run yourself, and how SmarterCSV handles each case. Note on CSV.table : It's a convenience wrapper for CSV.read with headers: true , header_converters: :symbol , and converters: :numeric . At a Glance # Ruby CSV Issue Failure Mode SmarterCSV fix SmarterCSV Details 1 Extra columns silently dropped Values beyond header count compete for the nil key — only the first survives, the
Continue reading on Dev.to
Opens in a new tab




