aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2012-01-27 03:19:53 -0600
committerJack Nagel2012-01-27 03:40:24 -0600
commit8944cc6b663318f94d20d92cd3b2716457ec37bb (patch)
tree7415b27f1275e86befddd1b5745d2b8e451a4b80
parentd10f2afbacbdd0cbe58c0be7c6384e98c576059b (diff)
downloadbrew-8944cc6b663318f94d20d92cd3b2716457ec37bb.tar.bz2
versions: fix up error handling
Now we handle some things more explicitly and in the process get rid of the blanket rescue on the mktemp block, which is something of an antipattern. By unloading the class *after* determining the version, we avoid the case where the class had previously been unloaded but Formula.factory failed, and trying to unload the nonexistent class results in a NameError. Doing it this way, we avoid having to rescue NameError and thereby avoid hiding other cases where it may occur. We also rescue TypeError which gets us past a few more bad formula in the history in some instances. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
-rw-r--r--Library/Homebrew/cmd/versions.rb20
1 files changed, 8 insertions, 12 deletions
diff --git a/Library/Homebrew/cmd/versions.rb b/Library/Homebrew/cmd/versions.rb
index 55703c811..101addb04 100644
--- a/Library/Homebrew/cmd/versions.rb
+++ b/Library/Homebrew/cmd/versions.rb
@@ -63,21 +63,17 @@ class Formula
path = Pathname.new(Pathname.pwd+"#{name}.rb")
path.write text_from_sha(sha)
- # Determine the version by loading the old class file.
- # Note that this means that the command will error out after it
- # encounters a formula that won't import. This doesn't matter
- # for most formulae, but e.g. Bash at revision aae084c9db has a
- # syntax error and so `versions` isn't able to walk very far back
- # through the history.
-
- # Unload the class so Formula#version returns the correct value.
+ # Unload the class so Formula#version returns the correct value
# FIXME shouldn't have to do this?
- Object.send(:remove_const, Formula.class_s(name))
begin
- nostdout { Formula.factory(path).version }
- rescue SyntaxError
+ version = nostdout { Formula.factory(path).version }
+ Object.send(:remove_const, Formula.class_s(name))
+ version
+ rescue SyntaxError, TypeError
+ # We rescue these so that we can skip bad versions and
+ # continue walking the history
nil
end
- end rescue nil
+ end
end
end