KubeMQ
Client SDKsRustReference

Types & Errors

KubemqError enum, ErrorCode, Result type alias, and common types

Result Type

The SDK defines a type alias for all operations:

pub type Result<T> = std::result::Result<T, KubemqError>;

Use the ? operator to propagate errors through kubemq::Result<()>.

KubemqError

The primary error type returned by all SDK operations. Each variant carries context including a machine-readable ErrorCode, human-readable message, and recovery suggestion.

VariantCodeRetryableDescription
TransientTransientYesTemporary failure (gRPC UNAVAILABLE, UNKNOWN, ABORTED)
TimeoutTimeoutYesOperation timed out (gRPC DEADLINE_EXCEEDED)
ThrottlingThrottlingYesRate limited (gRPC RESOURCE_EXHAUSTED)
AuthenticationAuthenticationNoInvalid/expired auth token (gRPC UNAUTHENTICATED)
AuthorizationAuthorizationNoInsufficient permissions (gRPC PERMISSION_DENIED)
ValidationValidationNoInvalid request (empty channel, bad params)
NotFoundNotFoundNoResource not found (gRPC NOT_FOUND)
FatalFatalNoUnrecoverable server error
CancellationCancellationNoOperation cancelled
BufferFullBackpressureNoInternal send buffer full
StreamBrokenTransientNoStream broken with unacknowledged messages
ClientClosedFatalNoClient has been closed
TransportFatalNoLow-level transport failure
HandlerFatalNoUser callback returned an error

Error Methods

MethodReturnsDescription
is_retryable()boolWhether the operation may succeed on retry
code()ErrorCodeMachine-readable error classification
suggestion()&strHuman-readable recovery guidance

Pattern Matching

main.rs
use kubemq::{ErrorCode, KubemqError};

match err.code() {
    ErrorCode::Transient => println!("Retry with backoff"),
    ErrorCode::Timeout => println!("Increase timeout"),
    ErrorCode::Authentication => println!("Check auth token"),
    ErrorCode::Validation => println!("Fix: {}", err.suggestion()),
    _ => println!("Error: {}", err),
}

Destructuring

main.rs
match result {
    Err(KubemqError::Validation { code, message, suggestion, .. }) => {
        println!("Code: {:?}, Message: {}, Suggestion: {}", code, message, suggestion);
    }
    Err(KubemqError::Transient { is_retryable, request_id, .. }) => {
        println!("Retryable: {}, Request: {}", is_retryable, request_id);
    }
    _ => {}
}

ErrorCode

Machine-readable error classification enum.

VariantgRPC CodesRetryable
TransientUNKNOWN, ABORTED, UNAVAILABLEYes
TimeoutDEADLINE_EXCEEDEDYes
ThrottlingRESOURCE_EXHAUSTEDYes
AuthenticationUNAUTHENTICATEDNo
AuthorizationPERMISSION_DENIEDNo
ValidationINVALID_ARGUMENT, ALREADY_EXISTS, FAILED_PRECONDITION, OUT_OF_RANGENo
NotFoundNOT_FOUNDNo
FatalUNIMPLEMENTED, INTERNAL, DATA_LOSSNo
CancellationCANCELLEDNo
BackpressureN/A (internal buffer full)No

Subscription

Handle returned by subscribe_to_* methods. Use it to cancel an active subscription.

MethodDescription
unsubscribe()Cancel the subscription and wait for cleanup
done()Wait until the subscription task completes

AsyncCallback

Type alias for subscription message handlers:

pub type AsyncCallback<T> =
    Box<dyn Fn(T) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>;

Used with Box::pin(async move { ... }) in subscription callbacks.

Was this page helpful?

On this page