{"record":{"id":"a9a0eacf92ccce80","repo":"ruby/rubygems","slug":"gemfile-not-found","errorCode":null,"errorMessage":"#{gemfile} not found","messagePattern":"#(.+?) not found","errorType":"exception","errorClass":"GemfileNotFound","httpStatus":null,"severity":"error","filePath":"lib/bundler/definition.rb","lineNumber":39,"sourceCode":"      :platforms,\n      :ruby_version,\n      :lockfile,\n      :gemfiles,\n      :sources\n    )\n\n    # Given a gemfile and lockfile creates a Bundler definition\n    #\n    # @param gemfile [Pathname] Path to Gemfile\n    # @param lockfile [Pathname,nil] Path to Gemfile.lock\n    # @param unlock [Hash, Boolean, nil] Gems that have been requested\n    #   to be updated or true if all gems should be updated\n    # @return [Bundler::Definition]\n    def self.build(gemfile, lockfile, unlock)\n      unlock ||= {}\n      gemfile = Pathname.new(gemfile).expand_path\n\n      raise GemfileNotFound, \"#{gemfile} not found\" unless gemfile.file?\n\n      Plugin.hook(Plugin::Events::GEM_BEFORE_EVAL, gemfile, lockfile)\n      Dsl.evaluate(gemfile, lockfile, unlock).tap do |definition|\n        Plugin.hook(Plugin::Events::GEM_AFTER_EVAL, definition)\n      end\n    end\n\n    #\n    # How does the new system work?\n    #\n    # * Load information from Gemfile and Lockfile\n    # * Invalidate stale locked specs\n    #  * All specs from stale source are stale\n    #  * All specs that are reachable only through a stale\n    #    dependency are stale.\n    # * If all fresh dependencies are satisfied by the locked\n    #  specs, then we can try to resolve locally.\n    #","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/ruby/rubygems/blob/86cbb817a38ce8477b181c17467a703ded3f2be8/lib/bundler/definition.rb#L21-L57","documentation":"Bundler::Definition.build is the entry point that turns a Gemfile plus optional lockfile into a Definition via Dsl.evaluate. It expands the gemfile path and requires an existing regular file (gemfile.file?), raising Bundler::GemfileNotFound with the expanded path otherwise (lib/bundler/definition.rb:39). The check runs before the Gemfile is parsed, so it is purely a path-existence failure: wrong path, dangling symlink, a directory, or a BUNDLE_GEMFILE pointing nowhere.","triggerScenarios":"BUNDLE_GEMFILE set to a nonexistent file (for example /app/Gemfile.production when only /app/Gemfile exists); calling Bundler::Definition.build(gemfile, lockfile, unlock) from Ruby with a bad path; deploy containers where the Gemfile was never COPYied to the location the env var names.","commonSituations":"Docker or CI images missing the Gemfile at the expected path; deploy configs referencing a templated Gemfile name that was never created; scripts run from a different working directory with stale absolute paths; repo restructuring breaking hardcoded paths.","solutions":["Verify the path exists: `ls -l \"$BUNDLE_GEMFILE\"` or check ./Gemfile in the current directory","Fix or unset BUNDLE_GEMFILE so it points at the real file: `export BUNDLE_GEMFILE=$(pwd)/Gemfile`","In Docker, COPY the Gemfile (and lockfile) into the image before any RUN bundle step","When calling Definition.build programmatically, guard with File.file?(gemfile) and pass an absolute path"],"exampleFix":"# before\nENV[\"BUNDLE_GEMFILE\"] = \"/app/Gemfile.production\" # does not exist\nBundler::Definition.build(ENV[\"BUNDLE_GEMFILE\"], nil, {})\n# => /app/Gemfile.production not found\n\n# after\nENV[\"BUNDLE_GEMFILE\"] = \"/app/Gemfile\"\nBundler::Definition.build(ENV[\"BUNDLE_GEMFILE\"], nil, {})","handlingStrategy":"validation","validationCode":"gemfile = Pathname.new(ENV.fetch(\"BUNDLE_GEMFILE\", Dir.pwd + \"/Gemfile\")).expand_path\nunless gemfile.file?\n  abort \"Gemfile not found at #{gemfile}; fix BUNDLE_GEMFILE or cwd\"\nend\ndefinition = Bundler::Definition.build(gemfile, gemfile.sub_ext(\".lock\"), {})","typeGuard":"# Predicate narrowing before calling the API\ndef loadable_gemfile?(path)\n  p = Pathname.new(path).expand_path\n  p.file? && p.readable?\nend\n\ndefinition = Bundler::Definition.build(gf, lf, {}) if loadable_gemfile?(gf)","tryCatchPattern":"begin\n  definition = Bundler::Definition.build(gemfile, lockfile, unlock)\nrescue Bundler::GemfileNotFound => e\n  abort \"bad bundle path: #{e.message}\"\nend","preventionTips":["Echo $BUNDLE_GEMFILE in CI logs before bundle steps","Validate required files at container build time, not runtime","Prefer running from the app root over hardcoded absolute Gemfile paths"],"tags":["bundler","gemfile","file-not-found","path","environment"],"backgroundTag":"missing-config-file","analyzedSha":"86cbb817a38ce8477b181c17467a703ded3f2be8","analyzedAt":"2026-08-23T06:27:48.159Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}