Closed rye closed 9 years ago
I just added a version to the Gemspec and that solved the issue. This should probably be checked for.
Gemspecs aren't valid without versions, so we should probably throw a useful error here.
On Mon, May 11, 2015 at 9:22 AM, Kristofer Rye notifications@github.com wrote:
I just added a version to the Gemspec and that solved the issue. This should probably be checked for.
Reply to this email directly or view it on GitHub: https://github.com/bundler/bundler/issues/3639#issuecomment-100969120
Exactly my thoughts. I haven't contributed to bundler yet, but I'd be glad to make it throw a useful error and submit that.
Maybe for non-rubygems deps, we could call spec.validate(false)
?
If I got it right, Gem::Specification::validate only exists for ruby > 1.9. Since we have travis for older versions, I suppose we should keep compatible? If is that so, maybe we should create our own validate method, that takes in account only things that we actually need, like version?
Or maybe we only validate when the method is available?
-Samuel E. Giddins
On May 11, 2015, at 5:28 PM, Felipe Tanus notifications@github.com wrote:
If I got it right, Gem::Specification::validate only exists for ruby > 1.9. Since we have travis for older versions, I suppose we should keep compatible? If is that so, maybe we should create our own validate method, that takes in account only things that we actually need, like version?
— Reply to this email directly or view it on GitHub.
I like @fotanus' idea; just check to see if spec.version
is non-nil, and, if not, complain. If there's anything else that we should check for, we can do that as well. The main goal is to eliminate the assumption that spec.version
is valid.
@fotanus @rye the rubygems_integration.rb
file handles the work of normalizing across different RubyGems versions. Create a valid_version?
method there, and implement it as a call to #validate or a nil check if #validate isn't present.
@indirect thanks for the guidance. I have been hacking this for some time now, and I don't think I found the correct place to put the test of a missing version. Is this right?
I can get a message of, but it is always on the eval line instead on the line mentionated on the issue. So maybe my test got other related issue?
However, I can reproduce the issue with the correct offending line pointed by the OP by using this:
bundle gem test_no_version
cd test_no_version/
sed -i -e "/spec.version/d" test_no_version.gemspec
bundle
@fotanus in 654e44a, I used the #validate
method to check on all specifications loaded by gemspec
. I also added a test to make sure that the right error would be raised by the method. I hope that makes sense!
Hi there,
yes, it makes sense! Thanks for showing me!
However, the spec I wrote still fails because of a nil version:
1) bundle install from an existing gemspec should raise if there is no version on the gemspec
Failure/Error: expect(error).to match(/version error message/)
expected "[!] There was an error parsing `Gemfile`: There was a NoMethodError while loading noversion.gemspec: \nundefined method `prerelease?' for nil:NilClass from\n /home/fotanus/code/bundler/tmp/noversion/noversion.gemspec:6:in `block in <main>'\n. Bundler cannot continue.\n\n # from /home/fotanus/code/bundler/tmp/bundled_app/Gemfile:2\n # -------------------------------------------\n # source \"file:///home/fotanus/code/bundler/tmp/gems/remote2\"\n > gemspec :path => '/home/fotanus/code/bundler/tmp/noversion'\n # -------------------------------------------" to match /version error message/
Diff:
@@ -1,2 +1,11 @@
-/version error message/
+[!] There was an error parsing `Gemfile`: There was a NoMethodError while loading noversion.gemspec:
+undefined method `prerelease?' for nil:NilClass from
+ /home/fotanus/code/bundler/tmp/noversion/noversion.gemspec:6:in `block in <main>'
+. Bundler cannot continue.
+
+ # from /home/fotanus/code/bundler/tmp/bundled_app/Gemfile:2
+ # -------------------------------------------
+ # source "file:///home/fotanus/code/bundler/tmp/gems/remote2"
+ > gemspec :path => '/home/fotanus/code/bundler/tmp/noversion'
+ # -------------------------------------------
Is it silly to care about this case or should I try to fix it?
@fotanus I think it's probably okay to stop here. With commit 654e44a, Bundler produces this output:
$ bundle check
[!] There was an error parsing `Gemfile`: The gemspec at /Users/andre/src/bundler/testcases/3639/foo/foo.gemspec is not valid. The validation error was 'missing value for attribute version'. Bundler cannot continue.
# from /Users/andre/src/bundler/testcases/3639/foo/Gemfile:4
# -------------------------------------------
# # Specify your gem's dependencies in foo.gemspec
> gemspec
# -------------------------------------------
when run on a Gemfile containing just gemspec
, in a folder with this foo.gemspec
:
Gem::Specification.new do |spec|
spec.name = "foo"
end
:+1:
What did you do?
I ran the command
bundle install
What did you expect to happen?
I expected Bundler to function properly and download and install all packages.
What happened instead?
Instead, I got this error.
Error details
Environment
Some further information:
I've got a Gemspec defined, but there isn't a version in it yet.