{"record":{"id":"8791c69a58a444f4","repo":"urbanadventurer/WhatWeb","slug":"unable-to-parse-invalid-target-no-hostname","errorCode":null,"errorMessage":"Unable to parse invalid target. No hostname.","messagePattern":"Unable to parse invalid target\\. No hostname\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/whatweb/scan.rb","lineNumber":281,"sourceCode":"              original_hostname = x.dup\n              # Add HTTPS version\n              https_version = \"https://#{x}\" \n              push_to_urllist << https_version\n              # add HTTP prefix to current target\n              x.sub!(/^/, 'http://')\n              # Provide informational message to user\n              debug(\"Simple hostname detected: #{original_hostname}. Testing both HTTP and HTTPS.\")\n            else\n              # For more complex paths, just use HTTP prefix as before\n              x.sub!(/^/, 'http://')\n            end\n          end\n\n          # is it a valid domain?\n          begin\n            domain = Addressable::URI.parse(x)\n            # check validity\n            raise 'Unable to parse invalid target. No hostname.' if domain.host.empty?\n\n            # convert IDN domain\n            x = domain.normalize.to_s if domain.host !~ %r{^[a-zA-Z0-9\\.:/]*$}\n            \n            # Reset counter on successful parse\n            consecutive_errors = 0\n          rescue => e\n            # Count consecutive errors\n            consecutive_errors += 1\n            \n            # Abort after 10 consecutive parsing errors\n            if consecutive_errors >= 10\n              error(\"Aborting target processing after #{consecutive_errors} consecutive parsing errors.\")\n              error(\"The input appears to contain invalid URLs or non-URL data.\")\n              error(\"Please check your input and ensure it contains valid URLs.\")\n              break\n            end\n            ","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/urbanadventurer/WhatWeb/blob/d279d93042d034f3fd29d5a893d44ccc0595d3f8/lib/whatweb/scan.rb#L263-L299","documentation":"make_target_list validates each target string by parsing it with Addressable::URI. If parsing succeeds but the resulting URI has an empty host (no hostname), WhatWeb raises 'Unable to parse invalid target. No hostname.' because it cannot resolve or connect to a target without a host.","triggerScenarios":"Passing a bare string without a host — e.g. '/path/only', 'http://', a stray filename or option value — into the target list so Addressable::URI.parse yields a URI with domain.host == '' or nil-adjacent emptiness.","commonSituations":"Operators forgetting the scheme+host (passing just a path); shell scripts passing empty strings from unset variables; target lists with blank lines or filenames accidentally included; ambiguity where the target regex matched a non-host string like an IP range fragment.","solutions":["Supply a full target with a hostname, e.g. http://example.com/ or example.com","Pre-validate each target: Addressable::URI.parse(x) and check !domain.host.to_s.empty? before running","Trim and skip empty/blank lines when reading targets from a file (x.split(/\\s+/).reject(&:empty?))","If the target was meant to be a local file or IP range, use the appropriate input form rather than a bare path string"],"exampleFix":"// before\nwhatweb /admin/login.php\n// after\nwhatweb http://example.com/admin/login.php","handlingStrategy":"validation","validationCode":"require 'addressable/uri'\ndef has_hostname?(s)\n  uri = Addressable::URI.parse(s.to_s)\n  !uri.host.to_s.empty?\nrescue Addressable::URI::InvalidURIError\n  false\nend","typeGuard":"def valid_target?(s)\n  s.is_a?(String) && !s.strip.empty? && has_hostname?(s)\nend","tryCatchPattern":"begin\n  WhatWeb::Scanner.new(targets)\nrescue RuntimeError => e\n  raise unless e.message.include?('Unable to parse invalid target')\n  warn 'Every target needs a hostname, e.g. http://example.com'\nend","preventionTips":["Always include scheme and host in targets (http://example.com)","Filter blank lines and stray paths out of target files","Validate each target with Addressable::URI.parse before running","Confirm the value passed is a target, not a filename or flag argument"],"tags":["ruby","whatweb","url-parsing","invalid-target","hostname"],"backgroundTag":"invalid-url-format","analyzedSha":"d279d93042d034f3fd29d5a893d44ccc0595d3f8","analyzedAt":"2026-09-15T13:51:42.453Z","contentChangedAt":"2026-09-15T13:51:42.453Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}