Last Updated: February 25, 2016
·
1.329K
· mxcl

`FileUtils.rmdir` Doesn’t `raise` if it Fails

This innocuous code:

FileUtils.rmdir('foo')

Will not raise if 'foo':

  1. Doesn't exist; or
  2. 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.