pub enum AmiError {
Provider {
provider: String,
message: String,
},
Serialization(Error),
InvalidParameter {
message: String,
},
OperationNotSupported {
operation: String,
},
ResourceNotFound {
resource: String,
},
PermissionDenied {
reason: String,
},
AccessDenied {
message: String,
},
ResourceLimitExceeded {
resource_type: String,
limit: usize,
},
ResourceExists {
resource: String,
},
StoreError(String),
UnreadablePolicy {
policy: String,
message: String,
},
UnreadableCondition {
policy: String,
statement: String,
message: String,
},
}Variants§
Provider
A provider rejected an operation.
Replaces the AwsSdk, StsSdk and SsoAdminSdk variants removed in 0.14. Those named SDK error types in their signature, so every consumer compiled three AWS SDKs to hold three variants this workspace never constructed once. Carrying the provider name and its message keeps the information without keeping the dependency:
client.get_user().send().await.map_err(|e| AmiError::Provider {
provider: "aws".to_string(),
message: e.to_string(),
})?Serialization(Error)
InvalidParameter
OperationNotSupported
ResourceNotFound
PermissionDenied
AccessDenied
ResourceLimitExceeded
ResourceExists
StoreError(String)
UnreadablePolicy
A policy document could not be parsed, so no decision can be made from it.
Deliberately an error and not a denial. A denial means “the rules
forbid this”; an unreadable policy means “the rules cannot be read” —
and the caller must be able to tell those apart, because the first is a
403 the user can act on and the second is a corrupt store that should
page someone. Folding it into AccessDenied would hide a broken policy
store behind what looks like an ordinary permission failure.
When several documents cannot be read, one error names them all, in
the authorizer’s canonical order: each field lists the documents’
values joined by "; ". The message names the statement (Sid, else
# and its index) and what the policy’s author wrote — never a value.
Fields
UnreadableCondition
A statement’s condition could not be evaluated, so no decision can be made from the policy that carries it.
Deliberately an error and not a false. A false condition means “the
statement does not apply here”; an unreadable one means “whether it
applies cannot be known” — and answering that as false made the
statement vanish, so a Deny carrying it stopped denying. As with
AmiError::UnreadablePolicy, it is not folded into AccessDenied
either: the policy is broken, and the operator must be told which one.
What still reaches evaluation after the parse check is the request
side — a value the operator cannot compare, such as an aws:SourceIp
that is no address, or a custom key holding a number under
StringEquals — or a document that did not go through
parse_policy_doc. Every statement whose action and resource match is
read before any verdict, so a Deny that holds does not hide one.
Several such statements are named in one error, in order, each field
listing the values joined by "; " (policy and statement pair up
by position). The message names kinds and positions, never the
request’s values.
Implementations§
Source§impl AmiError
Helper functions for creating common AmiError variants
impl AmiError
Helper functions for creating common AmiError variants
Sourcepub fn resource_not_found(resource_type: &str, resource_id: &str) -> AmiError
pub fn resource_not_found(resource_type: &str, resource_id: &str) -> AmiError
Create a “Resource not found” error with a formatted message
§Example
use wami_core::error::AmiError;
let error = AmiError::resource_not_found("User", "alice");
assert!(error.to_string().contains("User: alice"));Sourcepub fn permission_denied(action: &str, resource: &str) -> AmiError
pub fn permission_denied(action: &str, resource: &str) -> AmiError
Create a “Permission denied” error with action and resource context
§Example
use wami_core::error::AmiError;
let error = AmiError::permission_denied("delete", "User: alice");
assert!(error.to_string().contains("Cannot delete"));Sourcepub fn access_denied(message: impl Into<String>) -> AmiError
pub fn access_denied(message: impl Into<String>) -> AmiError
Create an “Access denied” error with a detailed message
§Example
use wami_core::error::AmiError;
let error = AmiError::access_denied("User alice does not have permission to delete users");Sourcepub fn invalid_parameter(message: impl Into<String>) -> AmiError
pub fn invalid_parameter(message: impl Into<String>) -> AmiError
Create an “Invalid parameter” error
§Example
use wami_core::error::AmiError;
let error = AmiError::invalid_parameter("User name cannot be empty");Sourcepub fn resource_exists(resource: impl Into<String>) -> AmiError
pub fn resource_exists(resource: impl Into<String>) -> AmiError
Create a “Resource already exists” error
§Example
use wami_core::error::AmiError;
let error = AmiError::resource_exists("User: alice");Trait Implementations§
Source§impl Error for AmiError
impl Error for AmiError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()