Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grape + Cucumber | number of arguments #2335

Open
rrmartins opened this issue Jun 7, 2023 · 3 comments
Open

Grape + Cucumber | number of arguments #2335

rrmartins opened this issue Jun 7, 2023 · 3 comments
Labels

Comments

@rrmartins
Copy link

hello, in my tests with cucumber I have a problem.

I'm getting a wrong number of arguments (given 1, expected 0) (ArgumentError) error when I try to make a request.

I make a request that is missing parameters, I should get a 400 error with the missing parameter message.

    params do
      requires :field_a, type: Integer
      requires :field_b, type: Integer
      requires :field_c, type: Float
      requires :field_d, type: Float
      optional :active, type: Boolean
    end
    post do
      result = WorkitProductCategory.create_or_update(params)
      present result, with: Api::V1::Entities::Pmp::WorkitProductCategoryObject
    end

so is my rescue_from:

  rescue_from Grape::Exceptions::ValidationErrors do |e|
      Rails.logger.debug(e)
      error!({ error: e.message, class: e.class.name, errors: e.errors }, e.status)
    end
@dblock
Copy link
Member

dblock commented Jun 7, 2023

What's the complete call stack?

@dblock dblock added the bug? label Jun 7, 2023
@rrmartins
Copy link
Author

I found the problem. inside the Grape::Exceptions::ValidationErrors return block, I had a Logger.debug. When doing an inspection of the running code, I noticed that there is something strange with the Rails.Logger.debug when the ValidationErrors object was sent. Then I realized that it was necessary to pass a "string" and not an object to be rendered.

# Before:
rescue_from Grape::Exceptions::ValidationErrors do |e|
      error = { error: e.message, class: e.class.name, errors: e.errors }

      Rails.logger.debug(e)

      Rack::Response.new(error.to_json, e.status)
end
# After:
rescue_from Grape::Exceptions::ValidationErrors do |e|
      error = { error: e.message, class: e.class.name, errors: e.errors }

      Rails.logger.debug(error.to_json) <----- HERE

      Rack::Response.new(error.to_json, e.status)
end

@dblock
Copy link
Member

dblock commented Jun 14, 2023

This could still be a bug. I expect Logger.debug(e) to work for Grape::Exceptions::ValidationErrors. Any interest in writing a spec for it and seeing if this is the case for all errors or just some errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants