SeleniumHQ/selenium · error · ArgumentError

unknown guard type: #{type}

Error message

unknown guard type: #{type}

What it means

Support::Guards::Guard#message maps a guard type Symbol to a human-readable message via a case statement covering :skip_if, :exclude, :flaky, :skip_unless, :exclusive, :pending_if, :pending_unless, :except, :only. Any other Symbol falls to the else branch and raises ArgumentError. This is internal test-infrastructure code (@api private) for RSpec integration-test guards, not user-facing library API.

Source

Thrown at rb/lib/selenium/webdriver/support/guards/guard.rb:63

                      when Integer
                        "Bug Filed: #{tracker}/#{reason}"
                      when Symbol
                        messages[reason]
                      else
                        "#{type.to_s.tr('_', ' ')} #{guarded};"
                      end

            case type
            when :skip_if, :exclude
              "Test skipped because it breaks test run; #{details}"
            when :flaky
              "Test skipped because it is unreliable in this configuration; #{details}"
            when :skip_unless, :exclusive
              "Test does not apply to this configuration; #{details}"
            when :pending_if, :pending_unless, :except, :only
              "Test guarded; #{details}"
            else
              raise ArgumentError, "unknown guard type: #{type}"
            end
          end

          # Test is expected to fail on the configurations specified (marked pending).
          def except?
            @type == :pending_if || @type == :except
          end

          # Test is expected to fail on every configuration except those specified (marked pending).
          def only?
            @type == :pending_unless || @type == :only
          end

          # Test is skipped on the configurations specified because it breaks the run or is unreliable.
          def exclude?
            @type == :skip_if || @type == :exclude || @type == :flaky
          end

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use one of the nine valid guard types: :skip_if, :exclude, :flaky, :skip_unless, :exclusive, :pending_if, :pending_unless, :except, :only.
  2. If extending guards, add the new type to the case statement in guard.rb:53-64 before using it.
  3. Check the guard key registered in spec/integration spec_helper matches the symbol you pass.

Example fix

# before
Guard.new(config, :skipp_if, guards).message

# after
Guard.new(config, :skip_if, guards).message
Defensive patterns

Strategy: validation

Validate before calling

VALID_GUARDS = %i[skip_if exclude flaky skip_unless exclusive pending_if pending_unless except only].freeze

raise ArgumentError, "bad guard #{type}" unless VALID_GUARDS.include?(type)
Guard.new(config, type, guards).message

Type guard

def valid_guard_type?(type)
  %i[skip_if exclude flaky skip_unless exclusive pending_if pending_unless except only].include?(type)
end

Prevention

When it happens

Trigger: Constructing a Selenium::WebDriver::Support::Guards::Guard with an unrecognized type Symbol (anything outside the nine known guard types) and then calling #message. Typically happens only when hand-rolling guard metadata or when RSpec metadata uses a guard key not registered in spec_helper.

Common situations: Contributors adding a new guard type but forgetting to add its case branch; typos in guard metadata (e.g. :skipp_if); programmatically building Guard objects from external metadata. End users of the webdriver library essentially never hit this.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/bb42e02c0859a6ab. Report an issue: GitHub.