team-formalist / formalist-rb

Flexible form builder
MIT License
22 stars 4 forks source link

Stop breaking apps already using dry-types #34

Closed timriley closed 3 years ago

timriley commented 8 years ago

Right now, if you use formalist inside a dry-web app that is already using dry-types, then you see errors like this:

/app/vendor/bundle/ruby/2.3.0/gems/dry-types-0.6.0/lib/dry/types/constructor.rb:54:in `method_missing': undefined method `const_set' for #<Dry::Types::Constructor:0x007faab43b5310> (NoMethodError)
Did you mean?  constrained
  from /app/vendor/bundle/ruby/2.3.0/gems/dry-types-0.6.0/lib/dry/types.rb:97:in `block in define_constants'
  from /app/vendor/bundle/ruby/2.3.0/gems/dry-types-0.6.0/lib/dry/types.rb:92:in `map'
  from /app/vendor/bundle/ruby/2.3.0/gems/dry-types-0.6.0/lib/dry/types.rb:92:in `define_constants'
  from /app/vendor/bundle/ruby/2.3.0/gems/dry-types-0.6.0/lib/dry/types.rb:43:in `module'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/types.rb:10:in `<module:Types>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/types.rb:9:in `<module:Formalist>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/types.rb:8:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/element.rb:3:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/element.rb:3:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/elements/attr.rb:1:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/elements/attr.rb:1:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/elements.rb:2:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/elements.rb:2:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/form.rb:2:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist/form.rb:2:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist.rb:1:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/formalist-661fc2f70c54/lib/formalist.rb:1:in `<top (required)>'
  from /app/lib/my_app/form.rb:1:in `require'
  from /app/lib/my_app/form.rb:1:in `<top (required)>'
  from /app/apps/admin/lib/admin/posts/forms/create_form.rb:1:in `require'
  from /app/apps/admin/lib/admin/posts/forms/create_form.rb:1:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:144:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:144:in `require_component'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:136:in `load_component'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:77:in `block (2 levels) in import_module'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:77:in `each'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:77:in `block in import_module'
  from /app/apps/admin/core/admin/import.rb:17:in `Import'
  from /app/apps/admin/lib/admin/views/posts/new.rb:8:in `<class:New>'
  from /app/apps/admin/lib/admin/views/posts/new.rb:7:in `<module:Posts>'
  from /app/apps/admin/lib/admin/views/posts/new.rb:6:in `<module:Views>'
  from /app/apps/admin/lib/admin/views/posts/new.rb:5:in `<module:Admin>'
  from /app/apps/admin/lib/admin/views/posts/new.rb:4:in `<top (required)>'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:90:in `require'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:90:in `block (2 levels) in auto_register!'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:87:in `tap'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:87:in `block in auto_register!'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:85:in `each'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:85:in `auto_register!'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:67:in `each'
  from /app/vendor/bundle/ruby/2.3.0/bundler/gems/dry-component-a7bb18a0d89f/lib/dry/component/container.rb:67:in `finalize!'
  from /app/apps/admin/core/boot.rb:3:in `<top (required)>'
  from /app/core/boot.rb:14:in `require'
  from /app/core/boot.rb:14:in `block in <top (required)>'
  from /app/core/boot.rb:14:in `each'
  from /app/core/boot.rb:14:in `<top (required)>'
  from ./bin/console:4:in `require_relative'
  from ./bin/console:4:in `<main>'

This error can be avoided by adding a core/boot/formalist.rb file with a single line to require formalist earlier in the app's boot process:

require "formalist"

But this feels hacky and unnecessary. It would be nice to figure out what the problem is here.