rust_releases_rust_dist/errors.rs
1use aws_config::InvalidAppName;
2use aws_sdk_s3::operation::list_objects_v2::ListObjectsV2Error;
3use rust_releases_core::Channel;
4
5/// A result type which binds the `RustDistError` to the error type.
6pub type RustDistResult<T> = Result<T, RustDistError>;
7
8/// Top level failure cases for rust-releases-rust-dist source crate
9///
10// FIXME: These should be enhanced by providing more detailed errors. We often simply bubble up
11// errors (like i/o) directly, but some of these do not provide enough information to be useful while
12// debugging (e.g. file not found, but which file?). In addition, they currently expose internals like
13// rusoto, which should be opaque, so the inner working can neatly be replaced without breaking changes.
14#[derive(Debug, thiserror::Error)]
15#[non_exhaustive]
16pub enum RustDistError {
17 /// Returned in case of an error related to the AWS SDK
18 #[error(transparent)]
19 AwsError(#[from] AwsError),
20
21 /// Returned in case a `Channel` is not available for the `Source`.
22 #[error("Channel {0} is not yet available for the 'RustDist' source type")]
23 ChannelNotAvailable(Channel),
24
25 /// Returned when the AWS Object returned does not have meta data. In such case
26 /// we can't get path of the object which we use to determine the release version.
27 #[error("Unable to obtain release metadata")]
28 ChunkMetadataMissing,
29
30 /// Returned when we can't consume the inner in-memory buffered writer.
31 #[error("Unable to flush chunk: '{0}'")]
32 ChunkWriteFlushError(#[from] std::io::IntoInnerError<std::io::BufWriter<Vec<u8>>>),
33
34 /// Returned in case of an i/o error.
35 #[error(transparent)]
36 Io(#[from] std::io::Error),
37
38 /// Returned in case of the base cache folder could not be found.
39 #[error(transparent)]
40 BaseCacheDir(#[from] rust_releases_io::BaseCacheDirError),
41
42 /// Returned when the staleness check fails.
43 #[error(transparent)]
44 IsStale(#[from] rust_releases_io::IsStaleError),
45
46 /// Returned in case the input text cannot be parsed.
47 #[error(transparent)]
48 UnrecognizedText(#[from] std::str::Utf8Error),
49
50 /// Returned in case a component of a `semver` version could not be parsed as a number.
51 ///
52 /// The component is usually the `major`, `minor` or `patch` version.
53 #[error("The '{0}' component of the version number could not be parsed. The input was: '{1}'")]
54 UnableToParseVersionNumberComponent(&'static &'static str, String),
55}
56
57/// Errors returned by the AWS SDK.
58#[derive(Debug, thiserror::Error)]
59pub enum AwsError {
60 #[error("Unable to build an anonymous AWS S3 request: failed to disable signing")]
61 DisableSigning,
62
63 /// Returned when the app name is invalid. Since the app name is configured by the library,
64 /// it's a bug when this error is returned.
65 #[error("Could not configure AWS S3 client: {0}")]
66 InvalidAppName(#[from] InvalidAppName),
67
68 /// Returned when it's not possible to list the S3 objects in the Rust bucket, required to
69 /// build our releases index.
70 #[error("Unable to fetch Rust distribution index: {0}")]
71 ListObjectsError(Box<ListObjectsV2Error>),
72
73 /// Failed to build the operation required to make an anonymous AWS S3 request.
74 #[error("Unable to make list objects operation")]
75 ListObjectsMakeOperation,
76}