Skip to content

IoError for NamedTempFile not passed by reference for FsBuilder.path #3495

@rogusdev

Description

@rogusdev

When using the FsBuilder.path, which is used by ByteStream::from_path, there can very easily be an unexpected error, that seems like it should be caught by the compiler rather than as a run time error.

A NamedTempFile argument must be passed by reference (i.e. with a leading &). If you remove the &, ByteStream::from_path (and FsBuilder.path) will accept the argument, but immediately error out with an IoError. You can demo this trivially with the existing tests, e.g. remove the & from &file on this line:

Then running the tests with:

cargo test byte_stream::bytestream_util --features rt-tokio,http-body-0-4-x,hyper-0-14-x

Will lead to this error:

---- byte_stream::bytestream_util::test::path_based_bytestreams_with_builder stdout ----
thread 'byte_stream::bytestream_util::test::path_based_bytestreams_with_builder' panicked at aws-smithy-types/src/byte_stream/bytestream_util.rs:328:14:
called `Result::unwrap()` on an `Err` value: Error { kind: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" }) }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Which seems very misleading, at best, and hopefully should be preventable at the compiler level by more appropriate typing -- or else adjusting as needed within the FsBuilder.path (or build) function.

Thanks!

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