uninitialized constant Webflow::Error
holden opened this issue · 6 comments
Hi, I've just tried starting to use your gem and I got stuck on an uninitialized error, it appears after the item is push into the job queue, so it shows up in sidekiq and I'm not able to debug the underlying error.
Rails 7.0.0
Ruby: 3.1.2
Sidekiq: 6.5.6
Any ideas?
Thanks
worker | 2022-09-21T10:23:33.103Z pid=65995 tid=h9z class=WebflowSync::UpdateItemJob jid=a89cf313155042c112cdb95b elapsed=0.912 INFO: fail
worker | 2022-09-21T10:23:33.103Z pid=65995 tid=h9z WARN: {"context":"Job raised exception","job":{"retry":true,"queue":"default","class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"WebflowSync::UpdateItemJob","args":[{"job_class":"WebflowSync::UpdateItemJob","job_id":"e7b1059d-94ed-4a4b-b5ea-af9b22b1dc67","provider_job_id":null,"queue_name":"default","priority":null,"arguments":["adventures",32],"executions":0,"exception_executions":{},"locale":"en","timezone":"Europe/Warsaw","enqueued_at":"2022-09-21T10:23:32Z"}],"jid":"a89cf313155042c112cdb95b","created_at":1663755812.190053,"enqueued_at":1663755812.190326}}
worker | 2022-09-21T10:15:49.101Z pid=57343 tid=25pn WARN: NameError: uninitialized constant Webflow::Error
worker |
worker | rescue Webflow::Error => e
worker | ^^^^^^^
worker | Did you mean? IOError
worker | Errno
/Users/holdenthomas/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/webflow_sync-b4b0d071d677/app/services/webflow_sync/api.rb:139:in `rescue in make_request': uninitialized constant Webflow::Error (NameError)
rescue Webflow::Error => e
^^^^^^^
Did you mean? IOError
Errno
/Users/holdenthomas/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/gems/webflow-ruby-0.7.0/lib/webflow/client.rb:87:in `update_item': wrong number of arguments (given 3, expected 2) (ArgumentError)
I narrowed down the error to the WebflowSync::Api.new
method which returns with no implicit conversion of String into Integer (TypeError)
even though everything is properly defined.
Example record.
irb(main):026:0> record=Adventure.order("RANDOM()").last
Adventure Load (1.2ms) SELECT "adventures".* FROM "adventures" ORDER BY RANDOM() DESC LIMIT $1 [["LIMIT", 1]]
=>
#<Adventure:0x000000010bcaea48
...
Returns json fine
irb(main):027:0> record.as_webflow_json
ActionText::RichText Load (1.2ms) SELECT "action_text_rich_texts".* FROM "action_text_rich_texts" WHERE "action_text_rich_texts"."record_id" = $1 AND "action_text_rich_texts"."record_type" = $2 AND "action_text_rich_texts"."name" = $3 LIMIT $4 [["record_id", 32], ["record_type", "Adventure"], ["name", "short_description"], ["LIMIT", 1]]
=>
{:name=>"Murder Mystery and the Zombie Apocalypse",
:slug=>"murder-mystery-and-the-zombie-apocalypse",
:description=>"Leave it to zombies and demons to ruin a perfectly good party!"}
Has a properly slugged name
irb(main):028:0> collection_slug = "Adventure".underscore.dasherize.pluralize
=> "adventures"
{"_id"=>"63286bfdfbf5570dcfa1eb0d",
"lastUpdated"=>"2022-09-19T13:17:50.540Z",
"createdOn"=>"2022-06-09T10:04:42.644Z",
"name"=>"Adventures",
"slug"=>"adventures",
"singularName"=>"Adventure"},
record.webflow_item_id
, record.webflow_site_id
and record.webflow_api_token
are all defined in the model, also site_id and token are also in the config file, seems to make no deference. I have checked using the webflow API with the same details and have no issues.
irb(main):041:0> c=WebflowSync::Api.new(record.webflow_site_id).update_item(record, collection_slug)
/Users/holdenthomas/.asdf/installs/ruby/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/webflow_sync-b4b0d071d677/app/services/webflow_sync/api.rb:118:in `block in find_webflow_collection': no implicit conversion of String into Integer (TypeError)
I've tried using 3.1, 4.0 and from master.
Any ideas?
Hey @holden!
I saw your message and forgot to get back to you. I'll check this issue tomorrow and give you an update.
Thanks for the patience! :)
No problem, thanks.
Hey @holden!
I checked what could be the issue. From what I can see, Webflow::Error
constant/class is not loaded in the code when the code tries to raise that error.
Looking further, I believe the error was being raised that Webflow::Client
constant is not loaded.
This is really odd, because WebflowSync
gem loads Webflow
gem as soon as it's loaded. Every gem in Gemfile
in a Rails app is automatically required (loaded) if it doesn't explicitly have require: false
.
lib/webflow_sync.rb
loads lib/webflow.rb
:
https://github.com/vfonic/webflow_sync/blob/master/lib/webflow_sync.rb#L6
Which loads the rest of the Webflow
('webflow-ruby'
) gem:
https://github.com/penseo/webflow-ruby/blob/master/lib/webflow.rb#L1
https://github.com/penseo/webflow-ruby/blob/master/lib/webflow/ruby.rb
I have pushed the fix and now I'm loading webflow/client
and webflow/error
explicitly in api.rb
. Hopefully that should fix it.
Otherwise, you could try adding gem 'webflow-ruby'
above/below gem 'webflow_sync'
in your Gemfile
.
Works great now. I was able to get everything working, thanks so much!
The changes you made actually made it completely stop working ;-), it wouldn't even load the console but it gave errors I could chase and I tried reversing the order in the gemfile as well as pulling the webflow gem from github.
I was using 0.4 but it wouldn't load, the updates you made in 4.0.1 forced it to crash, it only seemed to work when loading the gem directly from github then it worked fine.
gem "webflow-ruby", github: "penseo/webflow-ruby"
Thanks again.
The version that I'm using in my project is webflow-ruby (1.2.1)
. Perhaps that was the whole issue.
Maybe you can fix the issue by ensuring you're using the latest version?
# Gemfile
gem 'webflow-ruby'
$ bundle update webflow-ruby