palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

Unexpected error: 'Gem's lib is not in the $LOAD_PATH: /var/task/vendor/bundle/ruby/2.7.0/gems/anyway_config-2.0.6/lib' #71

Closed mt-kelvintaywl closed 3 years ago

mt-kelvintaywl commented 3 years ago

Hi @palkan , sorry for the ping but I was wondering if you can point me to a right way to resolve this? 🙏 thank you so much!

What did you do?

I am using anyway_config gem as a dependency in an AWS Lambda function. For context, the Ruby runtime env for the Lambda is Ruby 2.7

My Gemfile includes

gem 'anyway_config', '2.0.6'
gem 'ruby-next-core', '>= 0.8.0'

I am not sure why when the Lambda is invoked, i am seeing error from Ruby-next from Anyway Config?

{
    "errorMessage": "Gem's lib is not in the $LOAD_PATH: /var/task/vendor/bundle/ruby/2.7.0/gems/anyway_config-2.0.6/lib",
    "errorType": "Init<RuntimeError>",
    "stackTrace": [
        "/var/task/vendor/bundle/ruby/2.7.0/gems/ruby-next-core-0.10.5/lib/ruby-next/language/setup.rb:53:in `setup_gem_load_path'",
        "/var/task/vendor/bundle/ruby/2.7.0/gems/anyway_config-2.0.6/lib/anyway_config.rb:6:in `<top (required)>'",
        "/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'",
        "/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'",
        "/var/task/lib/client/directory.rb:4:in `<top (required)>'",
        "/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'",
        "/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'",
        "/var/task/lib/signals/handler.rb:10:in `<top (required)>'",
        "/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'",
        "/var/lang/lib/ruby/site_ruby/2.7.0/rubygems/core_ext/kernel_require.rb:72:in `require'"
    ]
}

What did you expect to happen?

the function should have executed successfully without this error. Forgive me for being ignorant, but I am also curious why the ruby-next lib is needed if the codebase using anyway_config is >= 2.7 ?

What actually happened?

Additional context

Environment

Ruby Version:

2.7.2

Framework Version (Rails, whatever):

-

Anyway Config Version:

2.0.6

palkan commented 3 years ago

I am also curious why the ruby-next lib is needed if the codebase using anyway_config is >= 2.7 ?

anyway_config uses some Ruby 3 syntax.

Gem's lib is not in the $LOAD_PATH

Hm, that's interesting.

How do you load the anyway_config gem? Could you print the contents of the $LOAD_PATH?

Also, take a look at this question and the code snippet: https://stackoverflow.com/a/53698808

mt-kelvintaywl commented 3 years ago

@palkan thank you for the quick response and suggestion.

Indeed, i examined the $LOAD_PATH in our Ruby Lambda and oddly, the gems' paths in $LOAD_PATH were with useless dots and slashes.

# examples
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/aws-sdk-core-3.72.0/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/jmespath-1.4.0/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/aws-sigv4-1.1.0/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/aws-partitions-1.230.0/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/aws-eventstream-1.0.3/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/ast-2.4.1/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/anyway_config-2.0.6/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/ruby-next-core-0.10.5/lib",
"/var/task/vendor/bundle/bundler/../ruby/2.7.0/gems/activesupport-6.0.3.2/lib",

for context, we use the Serverless framework to package & deploy our functions. We also use the ruby-package plugin for packaging dependencies. As a requirement of that plugin, we needed to use bundler in standalone mode. I wonder if that meant the load paths ended up as above? 🤔

I managed to have this worked around with another throwaway Lambda where:

cleaned = $LOAD_PATH.map { |path| Pathname.new(path).cleanpath }
$LOAD_PATH.unshift(*cleaned)

As such, this is indeed, not an issue on anyway_config nor ruby-next itself, so I will close this indeed 🙇

Thank you so much for your help as always! Really appreciate it!