Skip to content
This repository was archived by the owner on Aug 20, 2021. It is now read-only.
This repository was archived by the owner on Aug 20, 2021. It is now read-only.

TempDir ignores errors in drop #5

Closed
@cmbrandenburg

Description

@cmbrandenburg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions