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

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.

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

§policy: String

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

§message: String

What the parser objected to.

§

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.

Fields

§policy: String

Which policy holds the statement.

§statement: String

The statement: its Sid, else # and its index in the document.

§message: String

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

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

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

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

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

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

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>) -> AmiError

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<(), Error>

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

impl Display for AmiError

Source§

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

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) -> AmiError

Converts to this type from the input type.
Source§

impl From<ConditionError> for AmiError

Source§

fn from(err: ConditionError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for AmiError

Source§

fn from(source: Error) -> AmiError

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.