socketry / cloudflare

An asynchronous Ruby wrapper for the CloudFlare V4 API.
138 stars 86 forks source link

No async task available! #58

Closed mperham closed 2 years ago

mperham commented 4 years ago
No async task available!
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-1.24.1/lib/async/task.rb:183:in `current'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-io-1.27.1/lib/async/io/host_endpoint.rb:53:in `connect'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-io-1.27.1/lib/async/io/ssl_endpoint.rb:90:in `connect'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-http-0.50.0/lib/async/http/endpoint.rb:201:in `connect'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-http-0.50.0/lib/async/http/client.rb:140:in `block in make_pool'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-pool-0.2.0/lib/async/pool/controller.rb:181:in `create_resource'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-pool-0.2.0/lib/async/pool/controller.rb:210:in `block in available_resource'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-1.24.1/lib/async/semaphore.rb:78:in `acquire'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-pool-0.2.0/lib/async/pool/controller.rb:191:in `available_resource'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-pool-0.2.0/lib/async/pool/controller.rb:166:in `wait_for_resource'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-pool-0.2.0/lib/async/pool/controller.rb:76:in `acquire'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-http-0.50.0/lib/async/http/client.rb:104:in `call'
/Users/mikeperham/.gem/ruby/2.6.3/gems/protocol-http-0.13.0/lib/protocol/http/middleware.rb:40:in `call'
/Users/mikeperham/.gem/ruby/2.6.3/gems/protocol-http-0.13.0/lib/protocol/http/accept_encoding.rb:48:in `call'
/Users/mikeperham/.gem/ruby/2.6.3/gems/protocol-http-0.13.0/lib/protocol/http/middleware.rb:40:in `call'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-rest-0.10.1/lib/async/rest/representation.rb:76:in `block (2 levels) in <class:Representation>'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-rest-0.10.1/lib/async/rest/representation.rb:92:in `value!'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-rest-0.10.1/lib/async/rest/representation.rb:107:in `value'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-rest-0.10.1/lib/async/rest/resource.rb:84:in `tap'
/Users/mikeperham/.gem/ruby/2.6.3/gems/async-rest-0.10.1/lib/async/rest/resource.rb:84:in `get'
/Users/mikeperham/.gem/ruby/2.6.3/gems/cloudflare-4.2.0/lib/cloudflare/paginate.rb:29:in `each'
/Users/mikeperham/.gem/ruby/2.6.3/gems/cloudflare-4.2.0/lib/cloudflare/zones.rb:80:in `each'
/Users/mikeperham/.gem/ruby/2.6.3/gems/cloudflare-4.2.0/lib/cloudflare/zones.rb:80:in `first'
/Users/mikeperham/.gem/ruby/2.6.3/gems/cloudflare-4.2.0/lib/cloudflare/zones.rb:80:in `find_by_name'
/Users/mikeperham/src/machine/Rakefile:18:in `dns_add'

I don't understand the migration policy for v4. If you are going to require connect to take a block, please break the old usage and raise an error with the fix. Instead I had to find this repo, find an associated issue and then realize that the semantics for connect had changed.

Something like this would help immensely:

raise "Cloudflare.connect takes a block in v4, see README at (link)" unless block_given?
ioquatix commented 4 years ago

Sorry, I'm not quite sure what is going on here, are you saying the API in v4 broke in a minor release, or broke between v3 and v4 and the documentation/behaviour could be improved?

mperham commented 4 years ago

I was using connect without a block in v3. It was working fine. I upgraded to v4 and it broke with the backtrace above. I switched to the block form and it solved the problem. Ergo I assume the major version bump was for the new style of usage but I was surprised that the old style wasn't explicitly broken to make the upgrade path clearer for users..

ioquatix commented 4 years ago

Okay, I see how this could be confusing.

The error message "No async task available!" tells you what is wrong but not how to rectify it.

It gave me an idea, maybe Ruby exceptions should include a URL field by default, which allows us to link them through to more documentation. It seems logical to me.

But short of that, what you need to do is use an Async do ... end block. Generally, for APIs, this is not needed since you'd probably be doing a set of operations in a "single transaction". That being said I completely agree that it's non-obvious what to do.

So, I'll try to fix this by documentation, some more examples, etc.

mperham commented 2 years ago

Ran into this again today. Upgraded all my gems and got the same behavior. Googled and found I was the first hit.

No async task available!
/Users/mperham/.gem/ruby/3.0.3/gems/async-1.30.3/lib/async/task.rb:189:in `current'
/Users/mperham/.gem/ruby/3.0.3/gems/async-io-1.33.0/lib/async/io/host_endpoint.rb:55:in `connect'
/Users/mperham/.gem/ruby/3.0.3/gems/async-io-1.33.0/lib/async/io/ssl_endpoint.rb:92:in `connect'
/Users/mperham/.gem/ruby/3.0.3/gems/async-http-0.56.6/lib/async/http/endpoint.rb:201:in `connect'
/Users/mperham/.gem/ruby/3.0.3/gems/async-http-0.56.6/lib/async/http/client.rb:199:in `block in make_pool'
/Users/mperham/.gem/ruby/3.0.3/gems/async-pool-0.3.10/lib/async/pool/controller.rb:254:in `create_resource'
/Users/mperham/.gem/ruby/3.0.3/gems/async-pool-0.3.10/lib/async/pool/controller.rb:305:in `get_resource'
/Users/mperham/.gem/ruby/3.0.3/gems/async-pool-0.3.10/lib/async/pool/controller.rb:271:in `block in available_resource'
/Users/mperham/.gem/ruby/3.0.3/gems/async-1.30.3/lib/async/semaphore.rb:80:in `acquire'
/Users/mperham/.gem/ruby/3.0.3/gems/async-pool-0.3.10/lib/async/pool/controller.rb:270:in `available_resource'
/Users/mperham/.gem/ruby/3.0.3/gems/async-pool-0.3.10/lib/async/pool/controller.rb:236:in `wait_for_resource'
/Users/mperham/.gem/ruby/3.0.3/gems/async-pool-0.3.10/lib/async/pool/controller.rb:96:in `acquire'
/Users/mperham/.gem/ruby/3.0.3/gems/async-http-0.56.6/lib/async/http/client.rb:106:in `call'
/Users/mperham/.gem/ruby/3.0.3/gems/protocol-http-0.22.6/lib/protocol/http/middleware.rb:50:in `call'
/Users/mperham/.gem/ruby/3.0.3/gems/protocol-http-0.22.6/lib/protocol/http/accept_encoding.rb:50:in `call'
/Users/mperham/.gem/ruby/3.0.3/gems/protocol-http-0.22.6/lib/protocol/http/middleware.rb:50:in `call'
/Users/mperham/.gem/ruby/3.0.3/gems/async-rest-0.12.4/lib/async/rest/representation.rb:103:in `block (2 levels) in <class:Representation>'
/Users/mperham/.gem/ruby/3.0.3/gems/async-rest-0.12.4/lib/async/rest/representation.rb:119:in `value!'
/Users/mperham/.gem/ruby/3.0.3/gems/async-rest-0.12.4/lib/async/rest/representation.rb:134:in `value'
<internal:kernel>:90:in `tap'
/Users/mperham/.gem/ruby/3.0.3/gems/async-rest-0.12.4/lib/async/rest/resource.rb:84:in `get'
/Users/mperham/.gem/ruby/3.0.3/gems/cloudflare-4.3.0/lib/cloudflare/paginate.rb:29:in `each'
mperham commented 2 years ago

Ah, it was another block of code I had not updated. Apologies. For anyone else:

-    client = Cloudflare.connect(key: CF_KEY, email: CF_EMAIL)
-    zone = client.zones.find_by_name("contribsys.com")
-    dns_records = zone.dns_records.all
-    dns_records.each do |elm|
-      puts elm
+    Cloudflare.connect(key: CF_KEY, email: CF_EMAIL) do |client|
+      zone = client.zones.find_by_name("contribsys.com")
+      zone.dns_records.each do |elm|
+        puts elm
+      end
     end
ioquatix commented 2 years ago

Awesome!