-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use
anyhow
to rewrite the error handling process
Signed-off-by: The1111mp <[email protected]>
- Loading branch information
Showing
8 changed files
with
126 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
use super::{anyhow, Result}; | ||
use super::{ExitStatus, OsStr, OsString}; | ||
|
||
use crate::{command as CommandTool, common::ENV_PATH}; | ||
|
||
pub(super) fn command(exe: &OsStr, args: &[OsString]) -> Result<ExitStatus, String> { | ||
pub(super) fn command(exe: &OsStr, args: &[OsString]) -> Result<ExitStatus> { | ||
if ENV_PATH.is_empty() { | ||
return Err(String::from("command not found: ") + exe.to_str().unwrap()); | ||
return Err(anyhow!("command not found: {:?}", exe)); | ||
} | ||
|
||
let child = CommandTool::create_command(exe) | ||
let status = CommandTool::create_command(exe) | ||
.env("PATH", ENV_PATH.clone()) | ||
.args(args) | ||
.status(); | ||
.status()?; | ||
|
||
match child { | ||
Ok(status) => Ok(status), | ||
Err(_) => Err(String::from("failed to execute process")), | ||
} | ||
Ok(status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.