{"record":{"id":"17ac80dcdc136ac9","repo":"SeleniumHQ/selenium","slug":"cookie-name-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Cookie name cannot be null or empty","messagePattern":"Cookie name cannot be null or empty","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/manager.rb","lineNumber":82,"sourceCode":"      #\n      # Get the cookie with the given name\n      #\n      # @param [String] name the name of the cookie\n      # @return [Hash] the cookie, or throws a NoSuchCookieError if it wasn't found.\n      #\n\n      def cookie_named(name)\n        convert_cookie(@bridge.cookie(name))\n      end\n\n      #\n      # Delete the cookie with the given name\n      #\n      # @param [String] name the name of the cookie to delete\n      #\n\n      def delete_cookie(name)\n        raise ArgumentError, 'Cookie name cannot be null or empty' if name.nil? || name.to_s.strip.empty?\n\n        @bridge.delete_cookie name\n      end\n\n      #\n      # Delete all cookies\n      #\n\n      def delete_all_cookies\n        @bridge.delete_all_cookies\n      end\n\n      #\n      # Get all cookies\n      #\n      # @return [Array<Hash>] list of cookies\n      #\n","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/manager.rb#L64-L100","documentation":"Manager#delete_cookie requires a non-nil, non-blank cookie name. It explicitly rejects nil, empty strings, and whitespace-only names by calling name.to_s.strip.empty?. This guards against sending an invalid delete request to the driver endpoint.","triggerScenarios":"Calling driver.manage.delete_cookie(nil). Passing an empty string delete_cookie('') or whitespace delete_cookie('   '). Reading a name from a variable that resolved to nil.","commonSituations":"Looping over a list of names that contains nil/blank entries. UI-driven input that yields an empty cookie name. Forgetting to check user input before deletion.","solutions":["Ensure the name variable is a non-empty String before calling delete_cookie.","Filter blank entries from the name list: names.compact.reject(&:empty?).","Default to a guard clause: next if name.nil? || name.strip.empty?"],"exampleFix":"# before\ndriver.manage.delete_cookie(name) # name may be nil\n\n# after\nif name && !name.to_s.strip.empty?\n  driver.manage.delete_cookie(name)\nend","handlingStrategy":"validation","validationCode":"next if name.nil? || name.to_s.strip.empty?\ndriver.manage.delete_cookie(name)","typeGuard":"def valid_cookie_name?(name)\n  name.is_a?(String) && !name.strip.empty?\nend","tryCatchPattern":"begin\n  driver.manage.delete_cookie(name)\nrescue ArgumentError => e\n  raise unless e.message.include?('null or empty')\n  # skip or log; name was invalid\nend","preventionTips":["Sanitize the name list with compact and reject(&:strip!.!) before looping.","Guard UI-derived names with a presence check.","Treat nil/blank names as no-ops in deletion loops."],"tags":["ruby","cookies","validation"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}