{"record":{"id":"a7e0a40585844beb","repo":"ruby-concurrency/concurrent-ruby","slug":"no-block-given-a7e0a4","errorCode":null,"errorMessage":"no block given","messagePattern":"no block given","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/maybe.rb","lineNumber":138,"sourceCode":"\n    # Create a new `Maybe` using the given block.\n    #\n    # Runs the given block passing all function arguments to the block as block\n    # arguments. If the block runs to completion without raising an exception\n    # a new `Just` is created with the value set to the return value of the\n    # block. If the block raises an exception a new `Nothing` is created with\n    # the reason being set to the raised exception.\n    #\n    # @param [Array<Object>] args Zero or more arguments to pass to the block.\n    # @yield The block from which to create a new `Maybe`.\n    # @yieldparam [Array<Object>] args Zero or more block arguments passed as\n    #   arguments to the function.\n    #\n    # @return [Maybe] The newly created object.\n    #\n    # @raise [ArgumentError] when no block given.\n    def self.from(*args)\n      raise ArgumentError.new('no block given') unless block_given?\n      begin\n        value = yield(*args)\n        return new(value, NONE)\n      rescue => ex\n        return new(NONE, ex)\n      end\n    end\n\n    # Create a new `Just` with the given value.\n    #\n    # @param [Object] value The value to set for the new `Maybe` object.\n    #\n    # @return [Maybe] The newly created object.\n    def self.just(value)\n      return new(value, NONE)\n    end\n\n    # Create a new `Nothing` with the given (optional) reason.","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/maybe.rb#L120-L156","documentation":"Concurrent::Maybe.from is a factory that runs a block (with optional args) in a protected way: if it returns, you get a Just(value); if it raises, you get a Nothing wrapping the exception. The block is the whole point, so calling it without one raises ArgumentError 'no block given'.","triggerScenarios":"Concurrent::Maybe.from(value) expecting Just(value) — wrong API; Maybe.from(*args) with the computation forgotten; storing the operation in a variable and passing it positionally.","commonSituations":"Confusing from with Maybe(value)/Maybe.new(value) which wrap an existing value; generic 'run op or capture error' helpers that take callables positionally; conditional code paths where the block is built only sometimes and ends up nil.","solutions":["To wrap an existing value, use Concurrent::Maybe.new(value) or Concurrent::Maybe(value) — not from","To run protected code, always give from a block: Maybe.from { risky } — extra args are passed to the block: Maybe.from(a, b) { |x, y| ... }","If the operation is a stored callable, pass it as a block: Maybe.from(&callable)"],"exampleFix":"# before\nresult = Concurrent::Maybe.from(42)\n\n# after\nresult = Concurrent::Maybe.new(42)      # wrap existing value\nresult = Concurrent::Maybe.from { 42 }   # run protected block","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'operation block required' unless block_given?\nConcurrent::Maybe.from(*args) { |*a| yield(*a) }\n# or, to wrap an existing value:\nConcurrent::Maybe.new(value)","typeGuard":"->(obj) { obj.respond_to?(:call) } # then Maybe.from(&obj)","tryCatchPattern":"begin\n  Concurrent::Maybe.from { risky }\nrescue ArgumentError => e\n  raise ArgumentError, 'Maybe.from needs a block' if /no block/.match?(e.message)\n  raise\nend","preventionTips":["Use Maybe.new/Maybe() for wrapping values; reserve from for protected block execution","Assert block_given? in helper methods that wrap Maybe.from","Pass stored callables as blocks with &"],"tags":["ruby","monads","error-handling","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"}