Changed String::from_utf8 to String::from_utf8_lossy

This commit is contained in:
Shunsuke Shibayama 2022-08-17 23:19:16 +09:00
parent 6921189a95
commit 667b905e36
3 changed files with 3 additions and 4 deletions

View file

@ -8,7 +8,7 @@ fn main() -> std::io::Result<()> {
.args(&["rev-parse", "--short", "HEAD"])
.output()
.expect("failed to get the git hash");
let git_hash_short = String::from_utf8(output.stdout).unwrap();
let git_hash_short = String::from_utf8_lossy(&output.stdout);
let now = datetime::now();
println!("cargo:rustc-env=GIT_HASH_SHORT={git_hash_short}");
println!("cargo:rustc-env=BUILD_DATE={now}");

View file

@ -13,8 +13,7 @@ pub fn now() -> String {
.output()
.expect("failed to execute process to get current time")
};
String::from_utf8(output.stdout.clone())
.unwrap_or_else(|_| String::from_utf8_lossy(&output.stdout[..]).to_string())
String::from_utf8_lossy(&output.stdout[..])
.trim_end()
.to_string()
}

View file

@ -87,7 +87,7 @@ pub fn eval_pyc<S: Into<String>>(file: S) -> String {
.expect("cannot execute python")
};
let out = out.wait_with_output().expect("python doesn't work");
String::from_utf8(out.stdout).expect("failed to decode python output")
String::from_utf8_lossy(&out.stdout).to_string()
}
pub fn exec_py(code: &str) {