mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 09:26:52 +00:00 
			
		
		
		
	agent/rustjail: Clean up error path in execute_hook()s async task
Clippy (in Rust 1.51 at least) has some complaints about this closure inside execute_hook() because it uses explicit returns in some places where it doesn't need them, because they're the last expression in the function. That isn't necessarily obvious from a glance, but we can make clippy happy and also make things a little clearer: first we replace a somewhat verbose 'match' using Option::ok_or_else(), then rearrange the remaining code to put all the error path first with an explicit return then the "happy" path as the stright line exit with an implicit return. fixes #1611 Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
		| @@ -1528,28 +1528,23 @@ async fn execute_hook(logger: &Logger, h: &Hook, st: &OCIState) -> Result<()> { | ||||
|  | ||||
|         match child.wait().await { | ||||
|             Ok(exit) => { | ||||
|                 let code = match exit.code() { | ||||
|                     Some(c) => c, | ||||
|                     None => { | ||||
|                         return Err(anyhow!("hook exit status has no status code")); | ||||
|                     } | ||||
|                 }; | ||||
|                 let code = exit | ||||
|                     .code() | ||||
|                     .ok_or_else(|| anyhow!("hook exit status has no status code"))?; | ||||
|  | ||||
|                 if code == 0 { | ||||
|                     debug!(logger, "hook {} exit status is 0", &path); | ||||
|                     return Ok(()); | ||||
|                 } else { | ||||
|                 if code != 0 { | ||||
|                     error!(logger, "hook {} exit status is {}", &path, code); | ||||
|                     return Err(anyhow!(nix::Error::from_errno(Errno::UnknownErrno))); | ||||
|                 } | ||||
|  | ||||
|                 debug!(logger, "hook {} exit status is 0", &path); | ||||
|                 Ok(()) | ||||
|             } | ||||
|             Err(e) => { | ||||
|                 return Err(anyhow!( | ||||
|                     "wait child error: {} {}", | ||||
|                     e, | ||||
|                     e.raw_os_error().unwrap() | ||||
|                 )); | ||||
|             } | ||||
|             Err(e) => Err(anyhow!( | ||||
|                 "wait child error: {} {}", | ||||
|                 e, | ||||
|                 e.raw_os_error().unwrap() | ||||
|             )), | ||||
|         } | ||||
|     }); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user