Skip to main content

make_error

Function make_error 

Source
pub fn make_error(
    req: &Msg,
    err_type: MsgType,
    error_code: i32,
    dyn_error_code: DynErrorCode,
    pool: &MbufPool,
) -> Msg
Expand description

Build a synthetic error response for req.

The constructed message inherits the request’s id (so the dispatcher can pair them), sets is_request to false, marks the response as in-error, stamps the error codes, and attaches the rendered wire-format error string in one or more mbufs taken from pool so the client driver actually has bytes to write back.

The wire formats produced are:

  • Redis (RESP):
    • RspRedisError: -Dynomite: <message>\r\n
    • RspRedisErrorErr: -ERR <message>\r\n
    • RspRedisErrorOom: -OOM <message>\r\n
    • RspRedisErrorBusy: -BUSY <message>\r\n
    • RspRedisErrorNoauth: -NOAUTH <message>\r\n
    • RspRedisErrorLoading: -LOADING <message>\r\n
    • RspRedisErrorBusykey: -BUSYKEY <message>\r\n
    • RspRedisErrorMisconf: -MISCONF <message>\r\n
    • RspRedisErrorNoscript: -NOSCRIPT <message>\r\n
    • RspRedisErrorReadonly: -READONLY <message>\r\n
    • RspRedisErrorWrongtype: -WRONGTYPE <message>\r\n
    • RspRedisErrorExecabort: -EXECABORT <message>\r\n
    • RspRedisErrorMasterdown: -MASTERDOWN <message>\r\n
    • RspRedisErrorNoreplicas: -NOREPLICAS <message>\r\n
  • Memcache (text):
    • RspMcServerError: SERVER_ERROR <message>\r\n
    • RspMcClientError: CLIENT_ERROR <message>\r\n
    • RspMcError: ERROR\r\n

<message> is DynErrorCode::message.

§Examples

use dynomite::io::mbuf::MbufPool;
use dynomite::msg::{response, DynErrorCode, Msg, MsgType};

let req = Msg::new(7, MsgType::ReqRedisGet, true);
let pool = MbufPool::default();
let rsp = response::make_error(
    &req,
    MsgType::RspRedisError,
    13,
    DynErrorCode::PeerHostDown,
    &pool,
);
assert_eq!(rsp.parent_id(), 7);
assert!(rsp.flags().is_error);
let bytes: Vec<u8> = rsp.mbufs().iter().flat_map(|b| b.readable().to_vec()).collect();
assert_eq!(bytes, b"-Dynomite: Peer Node is down\r\n".to_vec());