faker-ruby/faker · error · ArgumentError

Familial connections can be left blank or #{familial_connect

Error message

Familial connections can be left blank or #{familial_connections.join(', ')}

What it means

Raised by Faker::Relationship.familial when the connection: argument, after downcasing, is not one of the keys under the faker.relationship.familial locale data (e.g. grandfather, grandmother, father, mother, son, daughter, brother, sister... depending on locale). Input is normalized with to_s.downcase, so 'Grandfather' works, but any unknown relation such as 'cousin' or 'aunt' raises ArgumentError listing the allowed connections.

Source

Thrown at lib/faker/default/relationship.rb:26

      ##
      # Produces a random family relationship.
      #
      # @return [String]
      #
      # @example
      #   Faker::Relationship.familial #=> "Grandfather"
      #
      # @faker.version 1.9.2
      def familial(connection: nil)
        familial_connections = translate('faker.relationship.familial').keys

        if connection.nil?
          connection = sample(familial_connections).to_s
        else
          connection = connection.to_s.downcase

          unless familial_connections.include?(connection.to_sym)
            raise ArgumentError,
                  "Familial connections can be left blank or #{familial_connections.join(', ')}"
          end
        end

        fetch("relationship.familial.#{connection}")
      end

      ##
      # Produces a random in-law relationship.
      #
      # @return [String]
      #
      # @example
      #   Faker::Relationship.in_law #=> "Brother-in-law"
      #
      # @faker.version 1.9.2
      def in_law
        fetch('relationship.in_law')

View on GitHub (pinned to cca4184947)

Solutions

  1. Call with connection: nil to get a random familial connection.
  2. Pass one of the listed (case-insensitive) connections such as 'grandfather' or :sister.
  3. Inspect the accepted set at runtime: Faker::Relationship.familial and mirror on the error message, or read the keys from the locale YAML.

Example fix

# before
Faker::Relationship.familial(connection: 'cousin') # ArgumentError (not in data)

# after
Faker::Relationship.familial # random
Faker::Relationship.familial(connection: 'grandfather')
Defensive patterns

Strategy: validation

Validate before calling

allowed = Faker::Relationship.familial_methods rescue nil
# simpler: read the locale keys directly
allowed = I18n.translate('faker.relationship.familial').keys.map(&:to_s)
Faker::Relationship.familial(connection: connection) if allowed.include?(connection.to_s.downcase)

Type guard

def known_familial_connection?(connection)
  I18n.translate('faker.relationship.familial').key?(connection.to_s.downcase.to_sym)
end

Try / catch

begin
  Faker::Relationship.familial(connection: connection)
rescue ArgumentError
  Faker::Relationship.familial # random fallback
end

Prevention

When it happens

Trigger: Faker::Relationship.familial(connection: 'cousin') or connection: :second_cousin raises when that key is absent from the loaded locale's relationship.familial section; connection: nil (default) samples a random one and never raises.

Common situations: Assuming the generator covers the full family tree (cousins/aunts/uncles are commonly missing); locale packs that ship a smaller familial set than en; passing values from a domain enum that is broader than Faker's list.

Related errors


AI-assisted analysis of faker-ruby/faker@cca4184947 (2026-08-21). Data as JSON: /api/errors/13e01903e0fe6854. Report an issue: GitHub.