Sha256: 22431cebea0467c98cf5fee4459f8ad4e762d7629c2000de0ace3c3aac08ca91

Contents?: true

Size: 740 Bytes

Versions: 6

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

module Switchman
  module StandardError
    def initialize(*args)
      # Shard.current can throw this when switchman isn't working right; if we try to
      # do our stuff here, it'll cause a SystemStackError, which is a pain to deal with
      if is_a?(::ActiveRecord::ConnectionNotEstablished)
        super
        return
      end

      begin
        @active_shards = Shard.active_shards if defined?(Shard)
      rescue ::ActiveRecord::ConnectionNotEstablished
        # If we hit an error really early in boot, activerecord may not be initialized yet
      end

      super
    end

    def current_shard(klass = ::ActiveRecord::Base)
      @active_shards&.[](klass) || Shard.default
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
switchman-3.0.11 lib/switchman/standard_error.rb
switchman-3.0.10 lib/switchman/standard_error.rb
switchman-3.0.9 lib/switchman/standard_error.rb
switchman-3.0.8 lib/switchman/standard_error.rb
switchman-3.0.7 lib/switchman/standard_error.rb
switchman-3.0.6 lib/switchman/standard_error.rb