-
Notifications
You must be signed in to change notification settings - Fork 237
Description
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:
| .path(&file) |
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!