rubygems / gemstash

A RubyGems.org cache and private gem server
MIT License
752 stars 120 forks source link

Fix uninitialized constant error when using Redis cache #375

Closed chris72205 closed 11 months ago

chris72205 commented 11 months ago

Description:

This change adds RedisClient to the autoload list. Without this change, an uninitialized constant error is raised when running setup and entering the redis cache (example output below). I also updated the default Redis connection string since the following error is thrown without having a scheme provided:

Error checking cache: Invalid URL: "localhost:6379"

I started to add tests, but couldn't reproduce it there without possibly affecting all tests. Since this line loads lib/gemstash/cache.rb, Gemstash::RedisClient becomes initialized.

bin/gemstash setup --debug --redo
Where should files go? [~/.gemstash]
Cache with what? [MEMORY, memcached, redis] redis
What is the comma-separated list of Redis servers? [localhost:6379]
What database adapter? [SQLITE3, postgres, mysql, mysql2]
Use Protected Fetch for Private Gems? [y/N] y
How many seconds to wait when fetching a gem? [20]
Checking that the cache is available
Error checking cache: uninitialized constant Gemstash::RedisClient
  [...]/gemstash/lib/gemstash/env.rb:174:in `cache_client'
  [...]/gemstash/lib/gemstash/cli/setup.rb:134:in `block in check_cache'
  [...]/gemstash/lib/gemstash/cli/setup.rb:187:in `with_new_config'
  [...]/gemstash/lib/gemstash/cli/setup.rb:194:in `try'
  [...]/gemstash/lib/gemstash/cli/setup.rb:134:in `check_cache'
  [...]/gemstash/lib/gemstash/cli/setup.rb:29:in `run'
  [...]/gemstash/lib/gemstash/cli.rb:74:in `setup'
  [...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/command.rb:27:in `run'
  [...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/invocation.rb:127:in `invoke_command'
  [...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor.rb:392:in `dispatch'
  [...]/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/thor-1.2.2/lib/thor/base.rb:485:in `start'
  [...]/gemstash/lib/gemstash/cli.rb:34:in `start'
  bin/gemstash:4:in `<main>'
The cache is not available

I will abide by the code of conduct.

th1agoalmeida commented 11 months ago

LGTM. Ran into the same issue locally. This fixes it.

th1agoalmeida commented 11 months ago

@olleolleolle you might want to take a look at this one too :)