tfparser_core/provider/error.rs
1//! Provider-resolver errors.
2//!
3//! Per [16-provider-resolver.md § 6]. Fatal failures (file I/O, validation
4//! that breaks an invariant) bubble through [`ProviderError`]. Recoverable
5//! anomalies (a profile that simply isn't in the map, an unrecognised role
6//! ARN) surface as [`crate::Diagnostic`]s on the workspace.
7//!
8//! [16-provider-resolver.md § 6]: ../../../specs/16-provider-resolver.md
9
10use std::{path::PathBuf, sync::Arc};
11
12use crate::error::ValidationError;
13
14/// Errors raised by the provider-resolver layer.
15#[derive(Debug, thiserror::Error)]
16#[non_exhaustive]
17pub enum ProviderError {
18 /// I/O failure reading `~/.aws/config` or a profile-map YAML file.
19 #[error("i/o error at {path}: {source}")]
20 Io {
21 /// Path the operation was attempting.
22 path: PathBuf,
23 /// Underlying I/O error.
24 #[source]
25 source: std::io::Error,
26 },
27
28 /// The configured profile-map file exceeded the size cap.
29 #[error("profile-map file at {path} is {observed} bytes, exceeds cap {limit}")]
30 FileTooLarge {
31 /// Offending path.
32 path: PathBuf,
33 /// Observed byte count.
34 observed: u64,
35 /// Limit in bytes.
36 limit: u64,
37 },
38
39 /// INI parse error (`~/.aws/config`).
40 #[error("ini parse error at {path}: {source}")]
41 Ini {
42 /// File the parser was reading.
43 path: PathBuf,
44 /// Underlying parser error.
45 #[source]
46 source: ini::ParseError,
47 },
48
49 /// YAML deserialise error.
50 #[error("yaml deserialise error at {path}: {source}")]
51 Yaml {
52 /// File path.
53 path: PathBuf,
54 /// Underlying parser error.
55 #[source]
56 source: serde_yaml::Error,
57 },
58
59 /// `validator` rejected a field in the profile-map YAML.
60 #[error("profile-map validation error in {path}: {source}")]
61 Validation {
62 /// File the field came from.
63 path: PathBuf,
64 /// Aggregated validation errors.
65 #[source]
66 source: validator::ValidationErrors,
67 },
68
69 /// An entry passed `validator` but failed our newtype check
70 /// (account-id / region length-charset). Carries the offending
71 /// profile name so the operator can fix the YAML.
72 #[error("profile-map entry `{profile}` rejected: {source}")]
73 InvalidEntry {
74 /// Offending profile name.
75 profile: Arc<str>,
76 /// Why it was rejected.
77 #[source]
78 source: ValidationError,
79 },
80
81 /// `source_profile` chain exceeded the hop cap (8 per spec § 3.1).
82 #[error(
83 "aws-config source_profile chain at `{profile}` exceeded {limit} hops (probable cycle)"
84 )]
85 ChainTooLong {
86 /// The profile that started the over-long chain.
87 profile: Arc<str>,
88 /// Configured hop cap.
89 limit: usize,
90 },
91
92 /// Resolver was configured in strict mode and one or more profiles
93 /// referenced from a `Workspace` had no entry in the profile map.
94 #[error("{count} unresolved profile(s) in strict mode (first: `{first}`)")]
95 StrictUnresolved {
96 /// Total unique unresolved profiles.
97 count: usize,
98 /// First profile encountered without a mapping.
99 first: Arc<str>,
100 },
101}
102
103/// Convenience alias.
104pub type Result<T> = std::result::Result<T, ProviderError>;