TempDir ignores errors in drop #5
Description
Any reason why TempDir
ignores errors when dropped?
I feel this is unsafe default behavior, as it could lead to a long-running process leaking temporary directories. To avoid this problem, a program must wrap TempDir
and have the wrapper call TempDir::close
in the wrapper's destructor—all to find out that an error occurred.
Here's an alternative. Suppose the TempDir
destructor panicks on error instead of silently squashing it. This means a program's default behavior is to be notified of the error. If a program must prevent panicking—for whatever reason—then that program could do the wrapper thing and squash the error in the wrapper's destructor.
The alternative strategy is safer, as it requires action on the part of the programmer to ignore errors instead of requiring action on the part of the programmer to be notified of errors. In the case of TempDir
's destructor, an error is probably a leak, the elimination of which is a big part of Rust's raison d'être.