Skip to main content

AmiError

Enum AmiError 

Source
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,
    },
}

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(),
})?

Fields

§provider: String

Which provider refused.

§message: String

What it said.

§

Serialization(Error)

§

InvalidParameter

Fields

§message: String
§

OperationNotSupported

Fields

§operation: String
§

ResourceNotFound

Fields

§resource: String
§

PermissionDenied

Fields

§reason: String
§

AccessDenied

Fields

§message: String
§

ResourceLimitExceeded

Fields

§resource_type: String
§limit: usize
§

ResourceExists

Fields

§resource: String
§

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.

Fields

§policy: String

Which policy failed to parse, so an operator knows what to fix.

§message: String

What the parser objected to.

Implementations§

Source§

impl AmiError

Helper functions for creating common AmiError variants

Source

pub fn resource_not_found(resource_type: &str, resource_id: &str) -> Self

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"));
Source

pub fn permission_denied(action: &str, resource: &str) -> Self

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"));
Source

pub fn access_denied(message: impl Into<String>) -> Self

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");
Source

pub fn invalid_parameter(message: impl Into<String>) -> Self

Create an “Invalid parameter” error

§Example
use wami_core::error::AmiError;

let error = AmiError::invalid_parameter("User name cannot be empty");
Source

pub fn resource_exists(resource: impl Into<String>) -> Self

Create a “Resource already exists” error

§Example
use wami_core::error::AmiError;

let error = AmiError::resource_exists("User: alice");
Source

pub fn resource_limit_exceeded(resource_type: &str, limit: usize) -> Self

Create a “Resource limit exceeded” error

§Example
use wami_core::error::AmiError;

let error = AmiError::resource_limit_exceeded("AccessKey", 2);
Source

pub fn operation_not_supported(operation: impl Into<String>) -> Self

Create an “Operation not supported” error

§Example
use wami_core::error::AmiError;

let error = AmiError::operation_not_supported("batch_delete");

Trait Implementations§

Source§

impl Debug for AmiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for AmiError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for AmiError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<ArnParseError> for AmiError

Source§

fn from(err: ArnParseError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for AmiError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.