Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Gracefully handle error in bundle gem #5358

Closed
nodo opened this issue Jan 24, 2017 · 4 comments
Closed

Gracefully handle error in bundle gem #5358

nodo opened this issue Jan 24, 2017 · 4 comments

Comments

@nodo
Copy link
Contributor

nodo commented Jan 24, 2017

  • What did you do?
$ mkdir issue
$ touch hello
$ bundle gem hello
  • What did you expect to happen?

Gracefully handle the fact that a file named hello already exist in the directory. Maybe ask user input about how to proceed. E.g. overwrite / abort.

  • What happened instead?

Bundler showed the unexpected error template.
I.e.

*Unfortunately, an unexpected error occurred, and Bundler cannot continue.* 

I would be happy to pick the issue if you wish. It does not seem a complex fix. What do you think?

Backtrace

Errno::EEXIST: File exists @ dir_s_mkdir - /private/tmp/bundler_issue/hello
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:228:in `mkdir'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:228:in `fu_mkdir'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:206:in `block (2 levels) in mkdir_p'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:204:in `reverse_each'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:204:in `block in mkdir_p'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:190:in `each'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/2.4.0/fileutils.rb:190:in `mkdir_p'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb:61:in `block in invoke!'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb:116:in `invoke_with_conflict_check'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb:60:in `invoke!'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/actions.rb:94:in `action'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb:25:in `create_file'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb:115:in `template'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/cli/gem.rb:125:in `block in run'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/cli/gem.rb:124:in `each'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/cli/gem.rb:124:in `run'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/cli.rb:433:in `run'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/cli.rb:20:in `dispatch'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/cli.rb:11:in `start'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/exe/bundle:32:in `block in <top (required)>'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
  /Users/anodari/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/bundler-1.14.2/exe/bundle:24:in `<top (required)>'
  /Users/anodari/.rbenv/versions/2.4.0/bin/bundle:22:in `load'
  /Users/anodari/.rbenv/versions/2.4.0/bin/bundle:22:in `<main>'

Environment

Bundler   1.14.2
Rubygems  2.6.8
Ruby      2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin15]
Git       2.10.0
Platform  x86_64-darwin-15
@segiddins
Copy link
Member

This could be fixed by using SharedHelpers.filesystem_access or checking and raising an exemption if an entry exists at that path.

Any interest in submitting a PR?

@nodo
Copy link
Contributor Author

nodo commented Jan 24, 2017

Thanks @segiddins , I will work on that and send a PR soon.

@nodo
Copy link
Contributor Author

nodo commented Jan 25, 2017

@segiddins While trying to debug this issue I found that this problem is related to a bug in Thor. I have opened a PR there: rails/thor#541.

In order to fix the bug properly I would change both thor and (slightly) bundler. I was wondering how does the integration between thor and bundler works. Can I change the thor code in lib/bundler/vendor/thor and submit a PR?

@segiddins
Copy link
Member

No, we have to wait until a Thor release upstream is made. In the meantime, we can try and wrap bundlers call with filesystem_access to provide more friendly errors

nodo pushed a commit to nodo/bundler that referenced this issue Feb 9, 2017
`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.
nodo pushed a commit to nodo/bundler that referenced this issue Feb 9, 2017
`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.
nodo pushed a commit to nodo/bundler that referenced this issue Feb 9, 2017
`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.
nodo pushed a commit to nodo/bundler that referenced this issue Feb 9, 2017
`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.
nodo pushed a commit to nodo/bundler that referenced this issue Feb 9, 2017
`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.
bundlerbot added a commit that referenced this issue Feb 10, 2017
…ddins

[Fix #5358] Handle files conflicts when using `bundle gem`

`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.

Fixes #5358
segiddins pushed a commit that referenced this issue Feb 12, 2017
…ddins

[Fix #5358] Handle files conflicts when using `bundle gem`

`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.

Fixes #5358

(cherry picked from commit f93accc)
Shekharrajak pushed a commit to Shekharrajak/bundler that referenced this issue Feb 20, 2017
`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.
hsbt pushed a commit to rubygems/bundler-graph that referenced this issue Oct 19, 2021
…ddins

[Fix #5358] Handle files conflicts when using `bundle gem`

`bundle gem` command fails with an exception when creating a gem having
the same name of a file in the specified path.

For instance:
> touch hello
> bundle gem hello

This bug is due to Thor gem. At the moment, Thor does not handle
conflicts between files and directories. This commit mitigates the
problem by rescuing the exception from Thor and gracefully exit with an
error message.

Fixes rubygems/bundler#5358
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants