oak
oak copied to clipboard
Handle errors gracefully
Currently, if any operation fails the whole process is terminated. Here's an example (on macOS):
$ ntree /dev
/dev
├── console
├── tty
├── null
├── zero
├── oslog
├── oslog_stream
├── fd
│ ├── 0
│ ├── 1
│ ├── 2
error: Failed to read dir '/dev/fd/3': Not a directory (os error 20)
tree handles this much nicer and continues iterating:
$ tree /dev
...
├── fbt
├── fd
│ ├── 0
│ ├── 1
│ ├── 2
│ └── 3 [error opening dir]
├── fsevents
...
A possible solution is adding a variant to tree::Event:
pub enum Event {
// ...
Error { error: std::error::Error, path: PathBuf }
}
and then handle this in TreeProcessor and PrintProcessor.
An open question is what type of error should be displayed. Personally, I don't like [error opening dir] that much since it provides no further info as to why the operation failed. A first version could probably just use the description of whatever std::error::Error is returned.