{"record":{"id":"a40db644447cb019","repo":"SeleniumHQ/selenium","slug":"file-not-added-for-reaping-file-inspect","errorCode":null,"errorMessage":"file not added for reaping: #{file.inspect}","messagePattern":"file not added for reaping: #(.+?)","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/file_reaper.rb","lineNumber":46,"sourceCode":"        attr_writer :reap\n\n        def reap?\n          @reap = defined?(@reap) ? @reap : true\n        end\n\n        def tmp_files\n          @tmp_files ||= Hash.new { |hash, pid| hash[pid] = [] }\n          @tmp_files[Process.pid]\n        end\n\n        def <<(file)\n          tmp_files << file\n        end\n\n        def reap(file)\n          return unless reap?\n\n          raise Error::WebDriverError, \"file not added for reaping: #{file.inspect}\" unless tmp_files.include?(file)\n\n          FileUtils.rm_rf tmp_files.delete(file)\n        end\n\n        def reap!\n          if reap?\n            tmp_files.each { |file| FileUtils.rm_rf(file) }\n            true\n          else\n            false\n          end\n        end\n      end\n\n      # we *do* want child process reaping, so not using Platform.exit_hook here.\n      at_exit { reap! }\n    end # FileReaper\n  end # WebDriver","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/file_reaper.rb#L28-L64","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nFileReaper.reap(tmp) # => WebDriverError: file not added for reaping\n\n# after\nFileReaper << tmp\nFileReaper.reap(tmp)","handlingStrategy":"validation","validationCode":"# Before calling FileReaper.reap(file) (internal use):\nif Selenium::WebDriver::FileReaper.reap? && Selenium::WebDriver::FileReaper.tmp_files.include?(file)\n  Selenium::WebDriver::FileReaper.reap(file)\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["file-reaper","temp-files","internal-api","ruby","lifecycle"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}