Elixir: Incorrect error message on File.rmdir! if it contains files

Created on 8 Oct 2016  路  5Comments  路  Source: elixir-lang/elixir

Environment

  • Elixir version (elixir -v): Elixir 1.3.3
  • Operating system: macOS 10.12

    Current behavior

iex(1)> File.mkdir!("tmp")                                                                                           
:ok                                                                                                                                                                                               
iex(2)> File.write!("tmp/file", <<1>>)                                                                               
:ok                                                                                                                  
iex(3)> File.rmdir!("tmp")                                                                                           
** (File.Error) could not remove directory "tmp": file already exists                                                
    (elixir) lib/file.ex:816: File.rmdir!/1

Expected behavior

iex(1)> File.mkdir!("tmp")                                                                                           
:ok                                                                                                                                                                                               
iex(2)> File.write!("tmp/file", <<1>>)                                                                               
:ok                                                                                                                  
iex(3)> File.rmdir!("tmp")                                                                                           
** (File.Error) could not remove directory "tmp": directory contains file(s)                                              
    (elixir) lib/file.ex:816: File.rmdir!/1

Most helpful comment

@eksperimental Given that rmdir example, I am convinced. Thank you. :heart:

All 5 comments

Unfortunately we are relaying the posix error message which is eexist: http://lxr.free-electrons.com/source/include/uapi/asm-generic/errno-base.h#L20

We could change it specially for rmdir! but I would prefer to note in the documentation rather than change the underlying unix error semantics.

I think we should tailor this particular message.
Current message is extremely disguising because it's telling you it cannot remove a dir, because this dir exists! WTH??!
It is not intuitive for users to go and read the documentation for rmdir when they see a message like this.

this is what GNU coreutils does

$ mkdir foo && touch foo/bar && rmdir foo
rmdir: failed to remove 'foo': Directory not empty

@eksperimental Given that rmdir example, I am convinced. Thank you. :heart:

I can take care of it if @Fahrradflucht is alright with it.

@eksperimental sure go ahead

Was this page helpful?
0 / 5 - 0 ratings

Related issues

josevalim picture josevalim  路  3Comments

andrewcottage picture andrewcottage  路  3Comments

vothane picture vothane  路  3Comments

DEvil0000 picture DEvil0000  路  3Comments

lukaszsamson picture lukaszsamson  路  3Comments