{"record":{"id":"b31783ed92674ff3","repo":"SeleniumHQ/selenium","slug":"invalid-port-port","errorCode":null,"errorMessage":"invalid port: #{@port}","messagePattern":"invalid port: #(.+?)","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/service.rb","lineNumber":86,"sourceCode":"\n      def initialize(path: nil, port: nil, log: nil, args: nil)\n        port ||= self.class::DEFAULT_PORT\n        args ||= []\n\n        @executable_path = path\n        @host = Platform.localhost\n        @port = Integer(port)\n        @log = case log\n               when :stdout\n                 $stdout\n               when :stderr\n                 $stderr\n               else\n                 log\n               end\n        @args = args\n\n        raise Error::WebDriverError, \"invalid port: #{@port}\" if @port < 1\n      end\n\n      def launch\n        @executable_path ||= DriverFinder.new(nil, self).driver_path\n        ServiceManager.new(self).tap(&:start)\n      end\n\n      def shutdown_supported\n        self.class::SHUTDOWN_SUPPORTED\n      end\n\n      private\n\n      def warn_driver_log_override\n        WebDriver.logger.warn('SE_DEBUG is set; overriding user-specified driver logging settings', id: :se_debug)\n      end\n    end # Service\n  end # WebDriver","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/service.rb#L68-L104","documentation":"Raised by Selenium::WebDriver::Service#initialize when the provided port, after conversion to Integer, is less than 1. This is a configuration validation: ports must be positive integers in the valid range (1-65535). The constructor calls Integer(port) first (which would raise ArgumentError for non-numeric input), then checks @port < 1.","triggerScenarios":"Passing port: 0 or a negative port number to Service.new. Passing port: nil when the Service subclass has no DEFAULT_PORT constant. Passing a string that converts to 0 or negative via Integer().","commonSituations":"Passing 0 intending 'auto-assign' (Service does not support this directly; it uses PortProber later). Misconfiguring from environment variables (e.g., ENV['PORT'].to_i when the env var is unset, yielding 0). Custom Service subclass missing the DEFAULT_PORT constant.","solutions":["Pass a valid port number (1-65535): Selenium::WebDriver::Service.chrome(port: 9515).","Pass nil to use the driver's DEFAULT_PORT constant.","If reading port from an env var, validate it: port = ENV.fetch('PORT', 9515).to_i; raise if port < 1."],"exampleFix":"// before\nservice = Selenium::WebDriver::Service.chrome(port: 0)\n# or accidentally:\nport = ENV['DRIVER_PORT'].to_i  # ENV unset => 0\nservice = Selenium::WebDriver::Service.chrome(port: port)\n\n// after\nservice = Selenium::WebDriver::Service.chrome(port: 9515)\n# or safely from env:\nport = ENV.fetch('DRIVER_PORT', 9515).to_i\nservice = Selenium::WebDriver::Service.chrome(port: port)","handlingStrategy":"validation","validationCode":"def valid_port?(port)\n  port = Integer(port) rescue nil\n  port && port.between?(1, 65535)\nend\n\nservice = Selenium::WebDriver::Service.chrome(port: valid_port?(my_port) ? my_port : nil)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass nil to Service.new to use the driver's DEFAULT_PORT instead of guessing.","Validate env-var-sourced ports before passing: port = ENV.fetch('PORT', 9515).to_i; raise if port < 1.","Use standard well-known ports for drivers (chromedriver: 9515, geckodriver: 4444, etc.)."],"tags":["service","port","configuration","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}