SeleniumHQ/selenium · error · Error::WebDriverError
file not added for reaping: #{file.inspect}
Error message
file not added for reaping: #{file.inspect} What it means
Raised as Error::WebDriverError by FileReaper.reap(file) when reap is enabled (default true) but the given file was never registered via FileReaper << (file). FileReaper is @api private, tracks temp files per Process.pid, and is invoked internally during driver teardown — end users essentially never call it directly.
Source
Thrown at rb/lib/selenium/webdriver/common/file_reaper.rb:46
attr_writer :reap
def reap?
@reap = defined?(@reap) ? @reap : true
end
def tmp_files
@tmp_files ||= Hash.new { |hash, pid| hash[pid] = [] }
@tmp_files[Process.pid]
end
def <<(file)
tmp_files << file
end
def reap(file)
return unless reap?
raise Error::WebDriverError, "file not added for reaping: #{file.inspect}" unless tmp_files.include?(file)
FileUtils.rm_rf tmp_files.delete(file)
end
def reap!
if reap?
tmp_files.each { |file| FileUtils.rm_rf(file) }
true
else
false
end
end
end
# we *do* want child process reaping, so not using Platform.exit_hook here.
at_exit { reap! }
end # FileReaper
end # WebDriverView on GitHub (pinned to aa36b38e69)
Solutions
- If you call FileReaper directly, always push before reaping: FileReaper << file; ... ; FileReaper.reap(file).
- In forked workers, do not reap files registered in the parent — either disable reaping (FileReaper.reap = false) or re-register the file in the child pid context first.
- If this surfaces from library internals, file a Selenium issue with the backtrace; do not work around it by mutating @tmp_files.
Example fix
# before FileReaper.reap(tmp) # => WebDriverError: file not added for reaping # after FileReaper << tmp FileReaper.reap(tmp)
Defensive patterns
Strategy: validation
Validate before calling
# Before calling FileReaper.reap(file) (internal use): if Selenium::WebDriver::FileReaper.reap? && Selenium::WebDriver::FileReaper.tmp_files.include?(file) Selenium::WebDriver::FileReaper.reap(file) end
Prevention
- Do not call FileReaper directly — it is @api private; let the driver/service teardown and the at_exit hook handle temp files.
- If you fork workers, disable reaping in children (FileReaper.reap = false) or re-register files under the child pid before reaping.
- Never reap the same path twice; track which paths you have pushed.
When it happens
Trigger: Calling FileReaper.reap(path) for a path that was not previously pushed with FileReaper << (path), or reaping after a fork where Process.pid differs (tmp_files is keyed by pid, so a child sees an empty list). Also reachable if internal code reaps a path twice.
Common situations: Almost always an internal-library bug or a forked-process teardown mismatch, not user-facing. Surfaces in test suites that fork workers, or when custom Service subclasses try to manage temp files themselves.
Related errors
- #{action.inspect} is not a valid action
- #{source.type} is not a valid input type
- #{source.type} is not a valid input type
- #{source.type} is not a valid input type
- #{source.type} is not a valid input type
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/a40db644447cb019.
Report an issue: GitHub.