summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-06-28 09:06:49 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-06-28 11:17:56 -0500
commitb13480f656e3ec3e39982eed81720862751ef9d0 (patch)
tree9159c36d2d4de513afcca5d3dfb8e6889bcd1055
parent58fc66897b156ce91eb98710f7708f8abe36c806 (diff)
downloadbundler-seg-error-registration.tar.gz
[Errors] Ensure no duplicate status codes are registeredseg-error-registration
-rw-r--r--lib/bundler/errors.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb
index 1f0f5f8201..7681ea73ae 100644
--- a/lib/bundler/errors.rb
+++ b/lib/bundler/errors.rb
@@ -3,6 +3,16 @@ module Bundler
class BundlerError < StandardError
def self.status_code(code)
define_method(:status_code) { code }
+ if match = BundlerError.all_errors.find {|_k, v| v == code }
+ error, _ = match
+ raise ArgumentError,
+ "Trying to register #{self} for status code #{code} but #{error} is already registered"
+ end
+ BundlerError.all_errors[self] = code
+ end
+
+ def self.all_errors
+ @all_errors ||= {}
end
end
@@ -41,7 +51,7 @@ module Bundler
class LockfileError < BundlerError; status_code(20); end
class CyclicDependencyError < BundlerError; status_code(21); end
class GemfileLockNotFound < BundlerError; status_code(22); end
- class PluginError < BundlerError; status_code(23); end
+ class PluginError < BundlerError; status_code(29); end
class GemfileEvalError < GemfileError; end
class MarshalError < StandardError; end