{"record":{"id":"a000df55d2f03759","repo":"urbanadventurer/WhatWeb","slug":"error-target-is-a-directory","errorCode":null,"errorMessage":"Error: #{@target} is a directory","messagePattern":"Error: #(.+?) is a directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/target.rb","lineNumber":186,"sourceCode":"    @is_url\n  end\n\n  def initialize(target = nil, redirect_counter = 0)\n    @target = target\n    @redirect_counter = redirect_counter\n    @headers = {}\n    @http_options = { method: 'GET' }\n    #\t\t@status=0\n\n    @is_url = if @target =~ /^http[s]?:\\/\\//\n                true\n              else\n                false\n              end\n\n    if File.exist?(@target)\n      @is_file = true\n      raise \"Error: #{@target} is a directory\" if File.directory?(@target)\n      if File.readable?(@target) == false\n        raise \"Error: You do not have permission to view #{@target}\"\n      end\n    else\n      @is_file = false\n    end\n\n    if is_url?\n      @uri = URI.parse(Addressable::URI.encode(@target))\n\n      # is this taking control away from the user?\n      # [400] http://www.alexa.com  [200] http://www.alexa.com/\n      @uri.path = '/' if @uri.path.empty?\n    else\n      # @uri=URI.parse(\"file://\"+@target)\n      @uri = URI.parse('')\n    end\n  end","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/urbanadventurer/WhatWeb/blob/d279d93042d034f3fd29d5a893d44ccc0595d3f8/lib/target.rb#L168-L204","documentation":"Raised in Target#initialize (lib/target.rb:186) when the target string or path supplied to Target.new points to an existing directory. WhatWeb targets must be a URL, a single file, or an IP/host — a directory cannot be opened or scanned, so construction aborts immediately.","triggerScenarios":"Target.new('some/dir') or running whatweb with a CLI argument that is an existing directory path (File.exist? true and File.directory? true).","commonSituations":"Passing a directory containing target files instead of the files themselves; forgetting to expand a glob ('./targets/*' unexpanded); typo where a path was meant to be a file; scripting that passes $PWD or a folder of exports as the target.","solutions":["Pass a single file or URL, not a directory","Enumerate the directory yourself and pass a file list (whatweb dir/* or build a target file with -i)","If you intended a URL list file, point to the file containing targets, not the folder holding it","Add a shell pre-check: [ -f \"$TARGET\" ] || [ -d \"$TARGET\" ] before invoking"],"exampleFix":"// before\nwhatweb ./targets/\n// after\nwhatweb ./targets/*.txt\n// or\nwhatweb --input-file=./targets/list.txt","handlingStrategy":"validation","validationCode":"target = ARGV[0]\nraise 'target is a directory' if File.directory?(target) rescue false\n# or in shell: [ -d \"$TARGET\" ] && echo 'pass a file or URL, not a directory'","typeGuard":"def scannable_target?(t)\n  t.is_a?(String) && !t.empty? && (t =~ URI::DEFAULT_PARSER.make_regexp || (File.file?(t) && File.readable?(t)))\nend","tryCatchPattern":"begin\n  target = Target.new(path)\nrescue RuntimeError => e\n  next unless e.message.include?('is a directory')\n  puts \"#{path} is a directory; expand to files first\"\nend","preventionTips":["Always expand globs before passing paths as targets","Use --input-file with a file listing targets rather than passing folders","Check File.file? vs File.directory? in wrapper scripts","Validate CLI arguments before invoking whatweb"],"tags":["filesystem","invalid-target","directory"],"backgroundTag":"path-is-not-a-directory","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"}