agardiner / csv-diff

Performs field-by-field diffs of CSV files
BSD 2-Clause "Simplified" License
45 stars 18 forks source link

error occurs when there is the null field #6

Open maeken2010 opened 7 years ago

maeken2010 commented 7 years ago

Hi

I'm using this tool for some csv files. then, I discover that error occurs when there is the null field. For example, if specifying these csv files, occurs NoMethodError.

a.csv

ID,description,
1,hoge,
2,huga,
3,poyo,

b.csv

ID,description
1,hoge
2,huge
3,piyo
diff = CSVDiff.new("a.csv", "b.csv")
NoMethodError: undefined method `upcase' for nil:NilClass

I think, to need rename fild nil to "NULL" in CSVSource. But, I dont think it's the best solution.

0x53A commented 6 years ago

I have the same issue (using https://github.com/agardiner/csv-diff-report as the front-end):

/home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-0.3.3/lib/csv-diff/csv_diff.rb:154:in `block in get_diff_fields': undefined method `upcase' for nil:NilClass (NoMethodError)
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-0.3.3/lib/csv-diff/csv_diff.rb:154:in `reject'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-0.3.3/lib/csv-diff/csv_diff.rb:154:in `get_diff_fields'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-0.3.3/lib/csv-diff/csv_diff.rb:89:in `initialize'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-report-0.3.4/lib/csv-diff-report/report.rb:221:in `new'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-report-0.3.4/lib/csv-diff-report/report.rb:221:in `diff_file'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-report-0.3.4/lib/csv-diff-report/report.rb:87:in `diff'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-report-0.3.4/lib/csv-diff-report/cli.rb:131:in `process'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-report-0.3.4/lib/csv-diff-report/cli.rb:101:in `run'
        from /home/lr/.rvm/gems/ruby-2.4.1/gems/csv-diff-report-0.3.4/bin/csvdiff:7:in `<top (required)>'
        from /home/lr/.rvm/gems/ruby-2.4.1/bin/csvdiff:23:in `load'
        from /home/lr/.rvm/gems/ruby-2.4.1/bin/csvdiff:23:in `<main>'
        from /home/lr/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
        from /home/lr/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'