`FileUtils.rmdir` Doesn’t `raise` if it Fails
This innocuous code:
FileUtils.rmdir('foo')
Will not raise if 'foo'
:
- Doesn't exist; or
- Cannot be removed because the directory is not empty.
Instead it returns an array of directories it failed to remove.
If you want an exception here, (because why wouldn't you?), then use Dir.rmdir
which behaves as one would expect.
The rationale for this insane decision is recorded here. Typically Ruby raises
in these sorts of situations IMO, so this email thread is good proof that you should keep a language’s stdlib small, and keep the list of people who can commit (and who decide how it works and what is in it) small.
Written by Max Howell
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#