Code Monkey home page Code Monkey logo

Comments (7)

kou avatar kou commented on July 21, 2024 2

Thanks.
It seems that it's an application specific error and it's not a general CSV error. So you should use your own error class instead of reusing CSV::MalformedCSVError.

from csv.

Mifrill avatar Mifrill commented on July 21, 2024 1

@kou well, in our specific case, we have a logic with check of valid headers

...
raise_malformed_csv_error unless valid_headers?
...

    def raise_malformed_csv_error
      raise CSV::MalformedCSVError
    end

    def valid_headers?
      has_required_columns? && has_only_supported_columns?
    end

So, I'm thinking about this error like a any error of CSV parsing, like a it's an explicit error, which was inherited from RuntimeError.

from csv.

kou avatar kou commented on July 21, 2024

Could you show codes that creating CSV::MalformedCSVError?

from csv.

Mifrill avatar Mifrill commented on July 21, 2024

@kou just this:

    def raise_malformed_csv_error
      raise CSV::MalformedCSVError
    end

with 2.6 ruby it's raised this:

     Failure/Error: raise CSV::MalformedCSVError
     
     ArgumentError:
       wrong number of arguments (given 0, expected 2)

because of this:
36e1cb2

csv/lib/csv.rb

Lines 212 to 219 in 36e1cb2

class MalformedCSVError < RuntimeError
attr_reader :line_number
alias_method :lineno, :line_number
def initialize(message, line_number)
@line_number = line_number
super("#{message} in line #{line_number}.")
end
end

For Ruby 2.5 code was without required arguments:

  # The error thrown when the parser encounters illegal CSV formatting.
  class MalformedCSVError < RuntimeError; end

  #

https://bugs.ruby-lang.org/issues/16133

from csv.

kou avatar kou commented on July 21, 2024

Thanks.
One more question. Why do you want to raise CSV::MalformedCSVError manually?

from csv.

Mifrill avatar Mifrill commented on July 21, 2024

@kou okay, thanks, I will take note and we will discuss it with colleagues. We've just got this error while ruby update. Now we'got how to resolve it. Thank you

from csv.

kou avatar kou commented on July 21, 2024

OK. I close this.

from csv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.