{"record":{"id":"6e9daa1003898643","repo":"ruby-concurrency/concurrent-ruby","slug":"no-block-given-6e9daa","errorCode":null,"errorMessage":"no block given","messagePattern":"no block given","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/future.rb","lineNumber":34,"sourceCode":"  # @!macro copy_options\n  #\n  # @see http://ruby-doc.org/stdlib-2.1.1/libdoc/observer/rdoc/Observable.html Ruby Observable module\n  # @see http://clojuredocs.org/clojure_core/clojure.core/future Clojure's future function\n  # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Future.html java.util.concurrent.Future\n  class Future < IVar\n\n    # Create a new `Future` in the `:unscheduled` state.\n    #\n    # @yield the asynchronous operation to perform\n    #\n    # @!macro executor_and_deref_options\n    #\n    # @option opts [object, Array] :args zero or more arguments to be passed the task\n    #   block on execution\n    #\n    # @raise [ArgumentError] if no block is given\n    def initialize(opts = {}, &block)\n      raise ArgumentError.new('no block given') unless block_given?\n      super(NULL, opts.merge(__task_from_block__: block), &nil)\n    end\n\n    # Execute an `:unscheduled` `Future`. Immediately sets the state to `:pending` and\n    # passes the block to a new thread/thread pool for eventual execution.\n    # Does nothing if the `Future` is in any state other than `:unscheduled`.\n    #\n    # @return [Future] a reference to `self`\n    #\n    # @example Instance and execute in separate steps\n    #   future = Concurrent::Future.new{ sleep(1); 42 }\n    #   future.state #=> :unscheduled\n    #   future.execute\n    #   future.state #=> :pending\n    #\n    # @example Instance and execute in one line\n    #   future = Concurrent::Future.new{ sleep(1); 42 }.execute\n    #   future.state #=> :pending","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/future.rb#L16-L52","documentation":"A Concurrent::Future wraps an asynchronous operation supplied at construction time, so Concurrent::Future.new requires a block. Without one it raises ArgumentError 'no block given' at creation — nothing is executed and no Future state is set.","triggerScenarios":"Concurrent::Future.new(callable) passing a Proc positionally; Concurrent::Future.new(executor: pool) with no operation block; constructing a Future intending to 'fill it in later' (that pattern is IVar).","commonSituations":"Migrating from hand-rolled Thread.new code where the callable is a variable; passing executor options but forgetting the operation; expecting Future to work like a placeholder container instead of an eager task description.","solutions":["Always give Future.new a block: Future.new { compute } — combine with options as Future.new(executor: pool) { compute }","If the operation is a stored callable, pass it as a block: Future.new(&callable)","For a write-once placeholder you complete manually, use Concurrent::IVar instead of Future","For immediate scheduling, use the Concurrent.future { ... } helper"],"exampleFix":"# before\nop = -> { fetch_data }\nf = Concurrent::Future.new(op)\n\n# after\nop = -> { fetch_data }\nf = Concurrent::Future.new(&op)","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'operation block required' unless block_given?\nConcurrent::Future.new(executor: executor) { yield }","typeGuard":"->(obj) { obj.respond_to?(:call) } # then Future.new(&obj)","tryCatchPattern":"begin\n  Concurrent::Future.new(&op)\nrescue ArgumentError => e\n  raise ArgumentError, 'Future needs an operation block' if /no block/.match?(e.message)\n  raise\nend","preventionTips":["Standardize on Concurrent.future { } for immediate use and Future.new(&op) for stored callables","If you need a manual placeholder, use Concurrent::IVar, not Future","Lint for Future.new calls with no block in code review"],"tags":["ruby","concurrency","future","block-argument","argument-validation"],"backgroundTag":"missing-block-argument","analyzedSha":"0b88d5ff75f69b3740c8f0868e76f833cb2fd45d","analyzedAt":"2026-08-21T20:12:56.291Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}