summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Wen <jrw2175@columbia.edu>2015-12-28 00:14:32 -0500
committerJames Wen <jrw2175@columbia.edu>2015-12-28 00:48:26 -0500
commitc87f9dd7dc5ef69506325d8c581198488a222d46 (patch)
tree308f96c424809cc985f07224d741528aed29da7c
parentba0bac9761408f98b9ca806bbfd52b1de414513d (diff)
downloadbundler-c87f9dd7dc5ef69506325d8c581198488a222d46.tar.gz
Create `TemporaryResourceError` that `SharedHelpers#filesystem_access` raises for `Errno::EAGAIN`
- Pull out `action` as an instance method of `PermissionError`
-rw-r--r--lib/bundler/errors.rb25
-rw-r--r--lib/bundler/shared_helpers.rb2
-rw-r--r--spec/bundler/definition_spec.rb10
3 files changed, 31 insertions, 6 deletions
diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb
index ea2b52a6fb..1c80b36f2e 100644
--- a/lib/bundler/errors.rb
+++ b/lib/bundler/errors.rb
@@ -58,13 +58,16 @@ module Bundler
@permission_type = permission_type
end
- def message
- action = case @permission_type
- when :read then "read from"
- when :write then "write to"
- when :executable, :exec then "execute"
- else @permission_type.to_s
+ def action
+ case @permission_type
+ when :read then "read from"
+ when :write then "write to"
+ when :executable, :exec then "execute"
+ else @permission_type.to_s
end
+ end
+
+ def message
"There was an error while trying to #{action} `#{@path}`. " \
"It is likely that you need to grant #{@permission_type} permissions " \
"for that path."
@@ -73,6 +76,16 @@ module Bundler
status_code(23)
end
+ class TemporaryResourceError < PermissionError
+ def message
+ "There was an error while trying to #{action} `#{@path}`. " \
+ "Some resource was temporarily unavailable. It's suggested that you try" \
+ "the operation again."
+ end
+
+ status_code(26)
+ end
+
class YamlSyntaxError < BundlerError
attr_reader :orig_exception
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index 2e512bfc74..35cbb9f0c5 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -114,6 +114,8 @@ module Bundler
yield path
rescue Errno::EACCES
raise PermissionError.new(path, action)
+ rescue Errno::EAGAIN
+ raise TemporaryResourceError.new(path, action)
end
private
diff --git a/spec/bundler/definition_spec.rb b/spec/bundler/definition_spec.rb
index 076f2c8632..8dc4bd28f0 100644
--- a/spec/bundler/definition_spec.rb
+++ b/spec/bundler/definition_spec.rb
@@ -19,5 +19,15 @@ describe Bundler::Definition do
to raise_error(Bundler::PermissionError, /Gemfile\.lock/)
end
end
+ context "when a temporary resource access issue occurs" do
+ subject { Bundler::Definition.new(nil, [], Bundler::SourceList.new, []) }
+
+ it "raises a TemporaryResourceError with explanation" do
+ expect(File).to receive(:open).with("Gemfile.lock", "wb").
+ and_raise(Errno::EAGAIN)
+ expect { subject.lock("Gemfile.lock") }.
+ to raise_error(Bundler::TemporaryResourceError, /temporarily unavailable/)
+ end
+ end
end
end