agent: propagate the internal detail errors to users

It's should propagate the detail errors to users when
the rpc call failed.

Fixes: #824

Signed-off-by: fupan.lfp <fupan.lfp@antfin.com>
This commit is contained in:
fupan.lfp 2020-09-30 00:01:23 +08:00
parent 3360fb343f
commit 4501c25a46

View File

@ -891,10 +891,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
let p = match find_process(&mut sandbox, cid.as_str(), eid.as_str(), false) {
Ok(v) => v,
Err(_) => {
Err(e) => {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::INVALID_ARGUMENT,
"invalid argument".to_string(),
format!("invalid argument: {:?}", e),
)));
}
};
@ -923,10 +923,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
let mut sandbox = s.lock().unwrap();
let p = match find_process(&mut sandbox, cid.as_str(), eid.as_str(), false) {
Ok(v) => v,
Err(_e) => {
Err(e) => {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::UNAVAILABLE,
"cannot find the process".to_string(),
format!("invalid argument: {:?}", e),
)));
}
};
@ -948,10 +948,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
};
let err = libc::ioctl(fd, TIOCSWINSZ, &win);
if let Err(_) = Errno::result(err).map(drop) {
if let Err(e) = Errno::result(err).map(drop) {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::INTERNAL,
"ioctl error".to_string(),
format!("ioctl error: {:?}", e),
)));
}
}
@ -976,10 +976,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
let iface = match rtnl.update_interface(interface.as_ref().unwrap()) {
Ok(v) => v,
Err(_) => {
Err(e) => {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::INTERNAL,
"update interface".to_string(),
format!("update interface: {:?}", e),
)));
}
};
@ -1005,10 +1005,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
// get current routes to return when error out
let crs = match rtnl.list_routes() {
Ok(routes) => routes,
Err(_) => {
Err(e) => {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::INTERNAL,
"update routes".to_string(),
format!("update routes: {:?}", e),
)));
}
};
@ -1037,10 +1037,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
let rtnl = sandbox.rtnl.as_mut().unwrap();
let v = match rtnl.list_interfaces() {
Ok(value) => value,
Err(_) => {
Err(e) => {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::INTERNAL,
"list interface".to_string(),
format!("list interface: {:?}", e),
)));
}
};
@ -1066,10 +1066,10 @@ impl protocols::agent_ttrpc::AgentService for agentService {
let v = match rtnl.list_routes() {
Ok(value) => value,
Err(_) => {
Err(e) => {
return Err(ttrpc::Error::RpcStatus(ttrpc::get_status(
ttrpc::Code::INTERNAL,
"list routes".to_string(),
format!("list routes: {:?}", e),
)));
}
};