SeleniumHQ/selenium · error · ArgumentError
Unknown pattern type: #{pattern_type}
Error message
Unknown pattern type: #{pattern_type} What it means
UrlPattern.format_pattern converts caller-supplied URL filters into the BiDi network interception wire shape. It only knows two strategies: :string (string match) and :url (parsed URL pattern). Any other pattern_type symbol raises ArgumentError. This is an internal helper used when building network intercept arguments.
Source
Thrown at rb/lib/selenium/webdriver/bidi/network/url_pattern.rb:39
module Selenium
module WebDriver
class BiDi
#
# @api private
#
module UrlPattern
module_function
def format_pattern(url_patterns, pattern_type)
case pattern_type
when :string
to_url_string_pattern(url_patterns)
when :url
to_url_pattern(url_patterns)
else
raise ArgumentError, "Unknown pattern type: #{pattern_type}"
end
end
def to_url_pattern(*url_patterns)
url_patterns.flatten.map do |url_pattern|
uri = URI.parse(url_pattern)
{
type: 'pattern',
protocol: uri.scheme || '',
hostname: uri.host || '',
port: uri.port.to_s,
pathname: uri.path || '',
search: uri.query || ''
}
end
end
View on GitHub (pinned to aa36b38e69)
Solutions
- Pass pattern_type: :string for substring/string match or pattern_type: :url for a parsed URL pattern.
- If you need a new kind, extend UrlPattern with a matching to_*_pattern method rather than passing an unknown type.
- Search your codebase for callers of format_pattern / add_intercept to find the bad type.
Example fix
// before UrlPattern.format_pattern(patterns, :regex) // after UrlPattern.format_pattern(patterns, :string)
Defensive patterns
Strategy: validation
Validate before calling
VALID_PATTERN_TYPES = %i[string url].freeze raise ArgumentError, 'bad pattern_type' unless VALID_PATTERN_TYPES.include?(pattern_type) UrlPattern.format_pattern(url_patterns, pattern_type)
Type guard
def valid_pattern_type?(t) %i[string url].include?(t) end
Try / catch
begin UrlPattern.format_pattern(patterns, type) rescue ArgumentError => e raise unless e.message =~ /Unknown pattern type/ type = :string retry end
Prevention
- Restrict callers to :string or :url via a constant whitelist.
- Treat format_pattern as internal API; do not pass user-supplied types directly.
- Add a unit test covering both valid types plus the rejection path.
When it happens
Trigger: Calling the internal format_pattern / network intercept API with a pattern_type other than :string or :url. Most often reached through a library bug or monkey-patch that passes :regex, :glob, :wildcard, or nil.
Common situations: Library internal misuse, downstream gem extending network interception with a custom type without patching format_pattern, typo in a fork.
Related errors
- Pattern must be an instance of UrlPattern. Received: '${patt
- Pattern must be an instance of UrlPattern. Received:'${patte
- Pattern must be an instance of String. Received:'${pattern}'
- Params must be an instance of AddInterceptParameters. Receiv
- Params must be an instance of ContinueRequestParameters. Rec
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/41d5e2e562061a17.
Report an issue: GitHub.