dotenv_validator icon indicating copy to clipboard operation
dotenv_validator copied to clipboard

[BUG] Integer values return Invalid format

Open JuanVqz opened this issue 1 year ago • 5 comments

IMPORTANT: please make sure you ask yourself all intro questions and fill all sections of the template.

Before we start...:

  • [x] I checked the documentation and found no answer
  • [x] I checked to make sure that this issue has not already been filed
  • [x] I'm reporting the issue to the correct repository (for multi-repository projects)

Version, Branch, or Commit:

dotenv_validator 1.0.0

Expected behavior:

Please include a detailed description of the behavior you were expecting when you encountered this issue.

Actual behavior:

Integer values

I have some integer values in my .env file

FOO=10                                                   #required,format=int

when starting the rails server (with Procfile.dev) it returns the following error, I'm not using docker.

09:33:06 web.1       | /Users/juanvqz/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/bundler/gems/dotenv_validator-dbfe346afdb8/lib/dotenv_validator.rb:73:in `check!': Environment variables with invalid format: FOO(RuntimeError)

Steps to reproduce:

  1. set some integer values in yout .env file
FOO=10    #required,format=int
  1. when starting the rails server (not using docker) it returns the following error.
09:33:06 web.1       | /Users/juanvqz/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/bundler/gems/dotenv_validator-dbfe346afdb8/lib/dotenv_validator.rb:73:in `check!': Environment variables with invalid format: FOO(RuntimeError)

Context and environment:

Provide any relevant information about your setup (Customize the list accordingly based on what info is relevant to this project)

  1. dotenv_validator 1.0.0
  2. Mac OS
  3. Sonoma
  4. 3.1.3

Delete any information that is not relevant.

Logs

Include relevant log snippets or files here.

I will abide by the code of conduct

JuanVqz avatar Nov 16 '23 16:11 JuanVqz

@JuanVqz I was trying to add a spec to cover your case. Theoretically, it must be like this if I'm not wrong https://gist.github.com/julioalucero/4b44268cdfcc478fd454ad81e012ff65, right?

If yes, the spec is green for Ruby 3.0 and 3.1.3, then I will try to reproduce it in a project.

julioalucero avatar Jul 11 '24 15:07 julioalucero

@julioalucero Yes, that looks like what @JuanVqz is describing

etagwerker avatar Jul 11 '24 15:07 etagwerker

Hey @julioalucero! if you have the FastRuby.io repository configured on your PC or any other project that uses this gem. Here are a few steps to follow:

  1. Add FOO=10 #required,format=int in the .env file.
  2. Run bin/start, which uses a Procfile.dev behind the scenes.
  3. See the error

@etagwerker thanks for confirming it :+1:

JuanVqz avatar Jul 11 '24 15:07 JuanVqz

@JuanVqz @etagwerker I made some discoveries:

  1. Are you using Foreman? I yes, try to start Rails without it. Example: bundle exec rails s -p 3000 -b 0.0.0.0. It should probably work now.
  2. Then, try doing: gem uninstall foreman (all versions) and then gem install foreman -v 0.76.0. It should probably work now too.
  3. Finally, on your config/application.rb, (below Bundler.require(*Rails.groups)) add this line: Dotenv::Railtie.overload. Then start your app using Foreman >= 0.78.0 and now it works 🥳

Explanation:

Apparently, the problem is that on Foreman 0.78.0 Dotenv was removed as a dependency (See comment here) and has its own processing.

Solution:

To resolve we can:

  1. Add to the Readme a recommendation to use foreman =< 0.76.0; but also:
  2. Recommend there to use Dotenv::Railtie.overload if you use foreman >= 0.78.0

Let me know what you think guys I can create a fixed PR with this solution and/or any other suggestion.

julioalucero avatar Aug 20 '24 14:08 julioalucero

@JuanVqz @etagwerker I made some discoveries:

  1. Are you using Foreman? I yes, try to start Rails without it. Example: bundle exec rails s -p 3000 -b 0.0.0.0. It should probably work now.
  2. Then, try doing: gem uninstall foreman (all versions) and then gem install foreman -v 0.76.0. It should probably work now too.
  3. Finally, on your config/application.rb, (below Bundler.require(*Rails.groups)) add this line: Dotenv::Railtie.overload. Then start your app using Foreman >= 0.78.0 and now it works 🥳

Explanation:

Apparently, the problem is that on Foreman 0.78.0 Dotenv was removed as a dependency (See comment here) and has its own processing.

Solution:

To resolve we can:

  1. Add to the Readme a recommendation to use foreman =< 0.76.0; but also:
  2. Recommend there to use Dotenv::Railtie.overload if you use foreman >= 0.78.0

Let me know what you think guys I can create a fixed PR with this solution and/or any other suggestion.

Hey @julioalucero, thank you for your research on this issue. I apologize for the delay in getting back to you.

I think adding a note in the README.md is a good idea. I feel that including Dotenv::Railtie.overload in the apps using our gem might be intrusive. Do you know if we can load the Dotenv::Railtie.overload command if we detect that the user's app is using Foreman >= 0.78.0 from our gem?

JuanVqz avatar Aug 27 '24 01:08 JuanVqz

@JuanVqz @etagwerker I made some discoveries:

  1. Are you using Foreman? I yes, try to start Rails without it. Example: bundle exec rails s -p 3000 -b 0.0.0.0. It should probably work now.

I recently worked on FastRuby.io, and I can confirm that it is true. When running the Rails server without Foreman, the error is not raised.

  1. Then, try doing: gem uninstall foreman (all versions) and then gem install foreman -v 0.76.0. It should probably work now too.

I had this foreman gem installed

gem list foreman

*** LOCAL GEMS ***
foreman (0.88.1)

and yes, installing and using gem install foreman -v 0.76.0 works, and the error is not raised.

  1. Finally, on your config/application.rb, (below Bundler.require(*Rails.groups)) add this line: Dotenv::Railtie.overload. Then start your app using Foreman >= 0.78.0 and now it works 🥳

I uninstalled foreman v0.76.0 to test this step which is also working as you mentioned.

Explanation:

Apparently, the problem is that on Foreman 0.78.0 Dotenv was removed as a dependency (See comment here) and has its own processing.

This is correct, Foreman 0.78.0+ doesn't have the dotenv dependency anymore which makes our application fail.

Solution:

To resolve we can:

  1. Add to the Readme a recommendation to use foreman =< 0.76.0; but also:
  2. Recommend there to use Dotenv::Railtie.overload if you use foreman >= 0.78.0

Let me know what you think guys I can create a fixed PR with this solution and/or any other suggestion.

After reviewing the issue you provided, I have identified a fix for our application. https://github.com/ombulabs/fastruby.io/pull/844

Additionally, it appears that dotenv_validator is not relevant to the problem, maybe we can close the issue

Thanks, @julioalucero, for doing the research on it! I really appreciate it. 🙏

cc @etagwerker thoughts?

JuanVqz avatar Oct 04 '24 16:10 JuanVqz

@JuanVqz @julioalucero Thanks for all this information!

I think it's okay to close this issue. It seems to be related to foreman and dotenv and not so much about the validator.

So it seems that this workaround makes everything go back to normal:

foreman start -f Procfile.dev --env .env.local

etagwerker avatar Oct 10 '24 02:10 etagwerker