fetlife/rollout · error · ArgumentError

context must be a Hash

Error message

context must be a Hash

What it means

Error "context must be a Hash" thrown in fetlife/rollout.

Source

Thrown at lib/rollout/logging.rb:160

          raise ArgumentError, "Invalid log event: #{event}"
        end

        expected_arity = method(event).arity
        unless args.count == expected_arity
          raise(
            ArgumentError,
            "Invalid number of arguments for event '#{event}': expected #{expected_arity} but got #{args.count}",
          )
        end

        public_send(event, *args)
      end

      CONTEXT_THREAD_KEY = :rollout_logging_context
      WITHOUT_THREAD_KEY = :rollout_logging_disabled

      def with_context(context)
        raise ArgumentError, "context must be a Hash" unless context.is_a?(Hash)
        raise ArgumentError, "block is required" unless block_given?

        Thread.current[CONTEXT_THREAD_KEY] = context
        yield
      ensure
        Thread.current[CONTEXT_THREAD_KEY] = nil
      end

      def current_context
        Thread.current[CONTEXT_THREAD_KEY] || {}
      end

      def without
        Thread.current[WITHOUT_THREAD_KEY] = true
        yield
      ensure
        Thread.current[WITHOUT_THREAD_KEY] = nil
      end

View on GitHub (pinned to bd318a9488)

Solutions

  1. Pass a Hash to with_context, e.g. Rollout::Logging.with_context({ user_id: 1 }) { ... }.
  2. Convert the value to a Hash before calling: with_context(context.to_h) { ... }.
  3. Verify no nil or non-Hash value (string, array) is passed as the context argument.

Example fix

Rollout::Logging.with_context({ user_id: user.id }) do
  rollout.activate(:new_ui)
end

When it happens

Trigger: Thrown at lib/rollout/logging.rb:160 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of fetlife/rollout@bd318a9488 (2026-08-23). Data as JSON: /api/errors/b213b6fb74e88dfd. Report an issue: GitHub.