dotenv_validator
dotenv_validator copied to clipboard
[BUG] Integer values return Invalid format
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:
- set some integer values in yout
.envfile
FOO=10 #required,format=int
- 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)
- dotenv_validator 1.0.0
- Mac OS
- Sonoma
- 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 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 Yes, that looks like what @JuanVqz is describing
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:
- Add
FOO=10 #required,format=intin the.envfile. - Run
bin/start, which uses a Procfile.dev behind the scenes. - See the error
@etagwerker thanks for confirming it :+1:
@JuanVqz @etagwerker I made some discoveries:
- 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. - Then, try doing:
gem uninstall foreman(all versions) and thengem install foreman -v 0.76.0. It should probably work now too. - Finally, on your
config/application.rb, (belowBundler.require(*Rails.groups)) add this line:Dotenv::Railtie.overload. Then start your app usingForeman >= 0.78.0and 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:
- Add to the Readme a recommendation to use
foreman =< 0.76.0; but also: - Recommend there to use
Dotenv::Railtie.overloadif you useforeman >= 0.78.0
Let me know what you think guys I can create a fixed PR with this solution and/or any other suggestion.
@JuanVqz @etagwerker I made some discoveries:
- 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.- Then, try doing:
gem uninstall foreman(all versions) and thengem install foreman -v 0.76.0. It should probably work now too.- Finally, on your
config/application.rb, (belowBundler.require(*Rails.groups)) add this line:Dotenv::Railtie.overload. Then start your app usingForeman >= 0.78.0and now it works 🥳Explanation:
Apparently, the problem is that on
Foreman 0.78.0Dotenv was removed as a dependency (See comment here) and has its own processing.Solution:
To resolve we can:
- Add to the Readme a recommendation to use
foreman =< 0.76.0; but also:- Recommend there to use
Dotenv::Railtie.overloadif you useforeman >= 0.78.0Let 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 @etagwerker I made some discoveries:
- 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.
- Then, try doing:
gem uninstall foreman(all versions) and thengem 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.
- Finally, on your
config/application.rb, (belowBundler.require(*Rails.groups)) add this line:Dotenv::Railtie.overload. Then start your app usingForeman >= 0.78.0and 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.0Dotenv 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:
- Add to the Readme a recommendation to use
foreman =< 0.76.0; but also:- Recommend there to use
Dotenv::Railtie.overloadif you useforeman >= 0.78.0Let 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 @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