jordansissel/fpm · error · FPM::Package::InvalidArgument

The given workdir '#{workdir}' must be a directory.

Error message

The given workdir '#{workdir}' must be a directory.

What it means

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.

Source

Thrown at lib/fpm/command.rb:310

                   "(stray flags found: #{stray_flags}")
    end

    # Some older behavior, if you specify:
    #   'fpm -s dir -t ... -C somepath'
    # fpm would assume you meant to add '.' to the end of the commandline.
    # Let's hack that. https://github.com/jordansissel/fpm/issues/187
    if input_type == "dir" and args.empty? and !chdir.nil?
      logger.info("No args, but -s dir and -C are given, assuming '.' as input")
      args << "."
    end

    if !File.exist?(workdir)
      logger.fatal("Given --workdir=#{workdir} is not a path that exists.")
      raise FPM::Package::InvalidArgument, "The given workdir '#{workdir}' does not exist."
    end
    if !File.directory?(workdir)
      logger.fatal("Given --workdir=#{workdir} must be a directory")
      raise FPM::Package::InvalidArgument, "The given workdir '#{workdir}' must be a directory."
    end

    logger.info("Setting workdir", :workdir => workdir)
    ENV["TMP"] = workdir

    validator = Validator.new(self)
    if !validator.ok?
      validator.messages.each do |message|
        logger.warn(message)
      end

      logger.fatal("Fix the above problems, and you'll be rolling packages in no time!")
      return 1
    end
    input_class = FPM::Package.types[input_type]
    output_class = FPM::Package.types[output_type]

    input = input_class.new

View on GitHub (pinned to b6d77ba72a)

Solutions

  1. Point --workdir at a real directory
  2. Move or delete the colliding file, then create the directory (mkdir -p)
  3. Check the flag value for typos or stray characters

Example fix

# before
fpm --workdir ./build.log -s dir -t deb ./app   # a file

# after
rm ./build.log && mkdir -p ./build && fpm --workdir ./build -s dir -t deb ./app
Defensive patterns

Strategy: validation

Validate before calling

workdir = File.expand_path(ENV.fetch('FPM_WORKDIR', 'build'))
abort '--workdir must point at a directory' unless File.directory?(workdir)
system('fpm', '--workdir', workdir, '-s', 'dir', '-t', 'deb', './app')

Try / catch

begin
  FPM::Command.run(argv)
rescue FPM::Package::InvalidArgument => e
  abort "--workdir invalid: #{e.message}"
end

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jordansissel/fpm@b6d77ba72a (2026-08-21). Data as JSON: /api/errors/ea727205f711fe74. Report an issue: GitHub.