rubyonjets/jets

YNAB gem not loading

Closed this issue · 3 comments

Checklist

  • Upgrade Jets: Are you using the latest version of Jets? This allows Jets to fix issues fast. There's a jets upgrade command that makes this a simple task. There's also an Upgrading Guide: http://rubyonjets.com/docs/upgrading/
  • Reproducibility: Are you reporting a bug others will be able to reproduce and not asking a question. If you're unsure or want to ask a question, do so on https://community.rubyonjets.com
  • Code sample: Have you put together a code sample to reproduce the issue and make it available? Code samples help speed up fixes dramatically. If it's an easily reproducible issue, then code samples are not needed. If you're unsure, please include a code sample.

My Environment

Software Version
Operating System Ubuntu 18.04
Jets 3.0.9
Ruby 2.7.3

Expected Behaviour

When the YNAB gem is in the Gemfile, it's loaded correctly into the project

Current Behavior

Trying to use the gem results in an error

{
  "errorMessage": "uninitialized constant YNAB",
  "errorType": "Function<NameError>",
  "stackTrace": []
}

Step-by-step reproduction instructions

  1. Create a new Jets project (example: jets new example-project)
  2. Add gem "ynab" to your Gemfile
  3. Create a job that tries to use the YNAB gem. Example:
# path: example-project/app/jobs/test_job.rb
# frozen_string_literal: true

class TestJob < ApplicationJob
  def run
    ynab = ::YNAB::API.new(ENV['YNAB_TOKEN'])
  end
end
  1. Run jets deploy
  2. Invoke the Lambda function with an empty event

I checked the Lambda layer and confirmed that the YNAB gem is there, so it's not a problem of Layer generation. Also, I use multiple other gems, but the YNAB one is the only that presents this problem. Additionally, I was already using the YNAB gem ~2 months ago and I didn't have any problem. I stopped executing that code path until 15-20 days ago, and then is when I started getting the errors.

The code that uses the gem has multiple tests, and those run perfectly fine both locally and in my CI environment (CircleCI). The problem is only present in Lambda.

Let me know if there is any additional information I can provide to help. Thanks in advance!

Adding the full error trace, in case it contains anything else that can be useful

Could not open library 'libcurl': libcurl: cannot open shared object file: No such file or directory.
Could not open library 'libcurl.so': libcurl.so: cannot open shared object file: No such file or directory.
Could not open library 'libcurl.so.4': libcurl.so.4: cannot open shared object file: No such file or directory
WARNING: Unable to require "bundler/setup"
There may be something funny with your ruby and bundler setup.
You can try upgrading bundler and rubygems:

    gem update --system
    gem install bundler

Here are some links that may be helpful:

* https://bundler.io/blog/2019/01/03/announcing-bundler-2.html
* https://community.rubyonjets.com/t/jets-1-9-8-install-issue-bundler-setup-missing/185/2

Also, running bundle exec in front of your command may remove this message.
START RequestId: b78c372f-bc17-42b1-9e65-5f4a5f5c9b25 Version: $LATEST
RubyError: NameError: uninitialized constant TestJob::YNAB
  /var/task/app/jobs/test_job.rb:5:in `run'
  /opt/ruby/gems/2.7.0/gems/jets-3.0.9/lib/jets/job/base.rb:25:in `process'
  app/jobs/test_job.rb:1:in `run'
  /opt/ruby/gems/2.7.0/gems/jets-3.0.9/lib/jets/processors/main_processor.rb:32:in `instance_eval'
  /opt/ruby/gems/2.7.0/gems/jets-3.0.9/lib/jets/processors/main_processor.rb:32:in `run'
  /opt/ruby/gems/2.7.0/gems/jets-3.0.9/lib/jets/core.rb:120:in `process'
  /var/task/handlers/jobs/test_job.rb:6:in `run'
  /var/runtime/lib/lambda_handler.rb:26:in `call_handler'
  /var/runtime/lib/runtime.rb:99:in `<main>'
Critical exception from handler
{
  "errorMessage": "uninitialized constant TestJob::YNAB",
  "errorType": "Function<NameError>",
  "stackTrace": [

  ]
}
END RequestId: b78c372f-bc17-42b1-9e65-5f4a5f5c9b25
REPORT RequestId: b78c372f-bc17-42b1-9e65-5f4a5f5c9b25	Duration: 23.42 ms	Billed Duration: 24 ms	Memory Size: 1536 MB	Max Memory Used: 154 MB	Init Duration: 2552.57 ms	
Unknown application error occurred
Function<NameError>

So this gem relies on libcurl system package but it doesn't specify it in its gemspec. Hence, jets does not detect that it's a native gem that requires some system packages.

Did a couple of things to make this happened, including adding an api call to the serverlessgems service for these special case gems. Jets will be better able to detect these special cases now and use a pre-compiled gem with the external package if possible. The ynab gem should work now.

Note: You will need Jets 3.0.11+

It works perfectly now, thanks a million for the help!