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

Better error reporting #13

Open
apohllo opened this issue Feb 15, 2022 · 1 comment
Open

Better error reporting #13

apohllo opened this issue Feb 15, 2022 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@apohllo
Copy link

apohllo commented Feb 15, 2022

Describe the bug

The error reporting when a function is wrongly composed is not useful.

To Reproduce

Let's take the example from the documentation

require 'dry/transformer'

class Mapper < Dry::Transformer::Pipe
  import Dry::Transformer::ArrayTransformations
  import Dry::Transformer::HashTransformations

  define! do
    map_array do
      symbolize_keys
      rename_keys :user_name, :name # the error is here!
      nest :address, [:city, :street, :zipcode]
    end
  end
end


mapper = Mapper.new

pp mapper.(
  [
    { 'user_name' => 'Jane',
      'city' => 'NYC',
      'street' => 'Street 1',
      'zipcode' => '123'
    }
  ]
)

Running the code gives:

Traceback (most recent call last):
	11: from example.rb:19:in `<main>'
	10: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/pipe.rb:71:in `call'
	 9: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/function.rb:50:in `call'
	 8: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/function.rb:50:in `call'
	 7: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/array.rb:45:in `map_array'
	 6: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/array.rb:45:in `map'
	 5: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/array.rb:45:in `block in map_array'
	 4: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/composite.rb:33:in `call'
	 3: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/composite.rb:33:in `call'
	 2: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/function.rb:50:in `call'
	 1: from /home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/function.rb:50:in `call'
/home/apohllo/.rvm/gems/ruby-2.7.2/gems/dry-transformer-0.1.1/lib/dry/transformer/hash.rb:170:in `rename_keys': wrong number of arguments (given 3, expected 2) (ArgumentError)

Expected behavior

I would like that the stack trace included the line that introduced the error, i.e. the line with the comment. But there is no reference to that line, making debugging of the composed code pretty hard. This stays in contrast with regular ruby code, which would directly indicate the line that has the error.

@apohllo apohllo added bug Something isn't working help wanted Extra attention is needed labels Feb 15, 2022
@solnic solnic added this to the 1.0.0 milestone Feb 16, 2022
@solnic
Copy link
Member

solnic commented Feb 16, 2022

Thanks! I'll make sure this is addressed for the 1.0.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants