mongodb/mongoid · error · Mongoid::Errors::EmptyConfigFile

Empty configuration file: %{path}.

Error message

Empty configuration file: %{path}.

What it means

Error "Empty configuration file: %{path}." thrown in mongodb/mongoid.

Source

Thrown at lib/mongoid/config/environment.rb:49

      # Load the yaml from the provided path and return the settings for the
      # specified environment, or for the current Mongoid environment.
      #
      # @example Load the yaml.
      #   Environment.load_yaml("/work/mongoid.yml")
      #
      # @param [ String ] path The location of the file.
      # @param [ String | Symbol ] environment Optional environment name to
      #   override the current Mongoid environment.
      #
      # @return [ Hash ] The settings.
      #
      # @api private
      def load_yaml(path, environment = nil)
        env = environment ? environment.to_s : env_name

        contents = File.read(path)
        raise Mongoid::Errors::EmptyConfigFile.new(path) if contents.empty?

        # These are the classes that can be used in a Mongoid
        # configuration file in addition to standard YAML types.
        permitted_classes = [
          # Symbols occur as values for read preference, for example.
          Symbol,
          # BSON::Binary occur as keyId values for FLE (more precisely,
          # the keyIds are UUIDs).
          BSON::Binary
        ]

        result = ERB.new(contents).result
        data = YAML.safe_load(result, permitted_classes: permitted_classes, aliases: true)

        raise Mongoid::Errors::InvalidConfigFile.new(path) unless data.is_a?(Hash)

        data[env]
      end

View on GitHub (pinned to 0da0e23d71)

When it happens

Trigger: Thrown at lib/mongoid/config/environment.rb:49 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of mongodb/mongoid@0da0e23d71 (2026-08-23). Data as JSON: /api/errors/8c2b8bd9ce3c151a. Report an issue: GitHub.