{"record":{"id":"19f621f466efd358","repo":"ruby-concurrency/concurrent-ruby","slug":"wrong-number-of-arguments-0-for-1","errorCode":null,"errorMessage":"wrong number of arguments (0 for 1+)","messagePattern":"wrong number of arguments \\(0 for 1\\+\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/immutable_struct.rb","lineNumber":85,"sourceCode":"    # @!macro struct_select\n    def select(&block)\n      return enum_for(:select) unless block_given?\n      ns_select(&block)\n    end\n\n    private\n\n    # @!visibility private\n    def initialize_copy(original)\n      super(original)\n      ns_initialize_copy\n    end\n\n    # @!macro struct_new\n    def self.new(*args, &block)\n      clazz_name = nil\n      if args.length == 0\n        raise ArgumentError.new('wrong number of arguments (0 for 1+)')\n      elsif args.length > 0 && args.first.is_a?(String)\n        clazz_name = args.shift\n      end\n      FACTORY.define_struct(clazz_name, args, &block)\n    end\n\n    FACTORY = Class.new(Synchronization::LockableObject) do\n      def define_struct(name, members, &block)\n        synchronize do\n          Synchronization::AbstractStruct.define_struct_class(ImmutableStruct, Synchronization::Object, name, members, &block)\n        end\n      end\n    end.new\n    private_constant :FACTORY\n  end\nend\n","sourceCodeStart":67,"sourceCodeEnd":102,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/immutable_struct.rb#L67-L102","documentation":"Concurrent::ImmutableStruct.new is the class-factory call (like Ruby's Struct.new): it defines a new immutable struct class from a list of member names. Passing zero arguments raises ArgumentError 'wrong number of arguments (0 for 1+)' because a struct with no members cannot be defined.","triggerScenarios":"Concurrent::ImmutableStruct.new with nothing after it; Concurrent::ImmutableStruct.new(*fields) where fields is an empty array (dynamic schemas, DB-driven columns); splatting a list that came back empty from an API or query result.","commonSituations":"Generating struct classes from data schemas (CSV headers, DB columns, JSON keys) where the source can legitimately be empty; refactoring member lists into constants and losing the contents; confusion between the factory call and instantiating the produced class.","solutions":["Ensure at least one member symbol/string is passed: Concurrent::ImmutableStruct.new(:a, :b)","When members come from a dynamic list, guard it first: raise a clear error (or skip creation) if the list is empty","Double-check splats: log fields.inspect before the call when the list is computed"],"exampleFix":"# before\nfields = query_columns(table) # => []\nKlass = Concurrent::ImmutableStruct.new(*fields)\n\n# after\nfields = query_columns(table)\nraise ArgumentError, \"#{table} has no columns; cannot build struct\" if fields.empty?\nKlass = Concurrent::ImmutableStruct.new(*fields)","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'at least one struct member required' if members.empty?\nKlass = Concurrent::ImmutableStruct.new(*members)","typeGuard":"->(list) { list.is_a?(Array) && list.all? { |m| m.is_a?(Symbol) || m.is_a?(String) } && !list.empty? }","tryCatchPattern":"begin\n  Concurrent::ImmutableStruct.new(*members)\nrescue ArgumentError => e\n  raise SchemaError, \"cannot define struct: #{e.message}\"\nend","preventionTips":["Validate dynamic schema lists (columns, keys) at the data boundary before generating classes","Cache generated struct classes keyed by the member list to avoid repeated metaprogramming","Fail with a domain-specific error that names the empty source (table, feed) instead of the raw ArgumentError"],"tags":["ruby","struct","immutability","argument-validation","metaprogramming"],"backgroundTag":"missing-required-argument","analyzedSha":"0b88d5ff75f69b3740c8f0868e76f833cb2fd45d","analyzedAt":"2026-08-21T20:12:56.291Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}