r-lib / fs

Provide cross platform file operations based on libuv.
https://fs.r-lib.org/
Other
365 stars 80 forks source link

Richer error objects #225

Open hadley opened 4 years ago

hadley commented 4 years ago

Consider:

library(fs)

path1 <- file_temp()
path2 <- file_temp()

str(rlang::catch_cnd(file_copy(path1, path2)))
#> List of 1
#>  $ message: chr "[ENOENT] Failed to copy '/tmp/Rtmpkbe5wh/filef26a706f1216' to '/tmp/Rtmpkbe5wh/filef26ac0c9c05': no such file or directory"
#>  - attr(*, "class")= chr [1:4] "ENOENT" "fs_error" "error" "condition"
#>  - attr(*, "location")= chr "file.cc:321"

Created on 2019-10-09 by the reprex package (v0.3.0)

I think ENOENT should be in a "error code" (or similar) field of the error object, and it would be nice to include the error path in the object

hadley commented 4 years ago

Probably should also consider conditionMessage() rather than building message in the constructor, since that's generally the path we're going in.