{"record":{"id":"ea727205f711fe74","repo":"jordansissel/fpm","slug":"the-given-workdir-workdir-must-be-a-directory","errorCode":null,"errorMessage":"The given workdir '#{workdir}' must be a directory.","messagePattern":"The given workdir '#(.+?)' must be a directory\\.","errorType":"validation","errorClass":"FPM::Package::InvalidArgument","httpStatus":null,"severity":"error","filePath":"lib/fpm/command.rb","lineNumber":310,"sourceCode":"                   \"(stray flags found: #{stray_flags}\")\n    end\n\n    # Some older behavior, if you specify:\n    #   'fpm -s dir -t ... -C somepath'\n    # fpm would assume you meant to add '.' to the end of the commandline.\n    # Let's hack that. https://github.com/jordansissel/fpm/issues/187\n    if input_type == \"dir\" and args.empty? and !chdir.nil?\n      logger.info(\"No args, but -s dir and -C are given, assuming '.' as input\")\n      args << \".\"\n    end\n\n    if !File.exist?(workdir)\n      logger.fatal(\"Given --workdir=#{workdir} is not a path that exists.\")\n      raise FPM::Package::InvalidArgument, \"The given workdir '#{workdir}' does not exist.\"\n    end\n    if !File.directory?(workdir)\n      logger.fatal(\"Given --workdir=#{workdir} must be a directory\")\n      raise FPM::Package::InvalidArgument, \"The given workdir '#{workdir}' must be a directory.\"\n    end\n\n    logger.info(\"Setting workdir\", :workdir => workdir)\n    ENV[\"TMP\"] = workdir\n\n    validator = Validator.new(self)\n    if !validator.ok?\n      validator.messages.each do |message|\n        logger.warn(message)\n      end\n\n      logger.fatal(\"Fix the above problems, and you'll be rolling packages in no time!\")\n      return 1\n    end\n    input_class = FPM::Package.types[input_type]\n    output_class = FPM::Package.types[output_type]\n\n    input = input_class.new","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/jordansissel/fpm/blob/b6d77ba72a560b687723376a0e5115c3a92634ad/lib/fpm/command.rb#L292-L328","documentation":"The companion validation for --workdir: the path exists but is not a directory (typically a regular file). Since fpm uses it as TMP/staging root, it must be a directory; otherwise a fatal log line and FPM::Package::InvalidArgument follow.","triggerScenarios":"Passing --workdir build.tar or any file path instead of a directory; a name collision where a file shadows the intended directory (e.g., a log file named like the workdir); trailing characters in the flag value.","commonSituations":"Copy-paste of a filename into --workdir; scripts deriving workdir from a variable that holds an artifact path; leftovers from earlier runs created as files.","solutions":["Point --workdir at a real directory","Move or delete the colliding file, then create the directory (mkdir -p)","Check the flag value for typos or stray characters"],"exampleFix":"# before\nfpm --workdir ./build.log -s dir -t deb ./app   # a file\n\n# after\nrm ./build.log && mkdir -p ./build && fpm --workdir ./build -s dir -t deb ./app","handlingStrategy":"validation","validationCode":"workdir = File.expand_path(ENV.fetch('FPM_WORKDIR', 'build'))\nabort '--workdir must point at a directory' unless File.directory?(workdir)\nsystem('fpm', '--workdir', workdir, '-s', 'dir', '-t', 'deb', './app')","typeGuard":null,"tryCatchPattern":"begin\n  FPM::Command.run(argv)\nrescue FPM::Package::InvalidArgument => e\n  abort \"--workdir invalid: #{e.message}\"\nend","preventionTips":["Assert File.directory?(workdir) before invoking fpm","Beware name collisions where an artifact file shadows the intended directory name","Check flag values for typos when copy-pasting commands"],"tags":["fpm","cli","workdir","path","argument-validation"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"b6d77ba72a560b687723376a0e5115c3a92634ad","analyzedAt":"2026-08-21T16:39:02.570Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}