Use from_utf8_lossy instead of from_utf8 everywhere

This commit is contained in:
Dheepak Krishnamurthy 2020-10-31 10:28:09 -06:00
parent 694ea0f351
commit 7706ae3cfe
3 changed files with 12 additions and 12 deletions

View file

@ -170,14 +170,14 @@ impl TTApp {
pub fn get_context(&mut self) -> Result<(), Box<dyn Error>> { pub fn get_context(&mut self) -> Result<(), Box<dyn Error>> {
let output = Command::new("task").arg("_get").arg("rc.context").output()?; let output = Command::new("task").arg("_get").arg("rc.context").output()?;
self.context_name = String::from_utf8(output.stdout)?; self.context_name = String::from_utf8_lossy(&output.stdout).to_string();
self.context_name = self.context_name.strip_suffix('\n').unwrap_or("").to_string(); self.context_name = self.context_name.strip_suffix('\n').unwrap_or("").to_string();
let output = Command::new("task") let output = Command::new("task")
.arg("_get") .arg("_get")
.arg(format!("rc.context.{}", self.context_name)) .arg(format!("rc.context.{}", self.context_name))
.output()?; .output()?;
self.context_filter = String::from_utf8(output.stdout)?; self.context_filter = String::from_utf8_lossy(&output.stdout).to_string();
self.context_filter = self.context_filter.strip_suffix('\n').unwrap_or("").to_string(); self.context_filter = self.context_filter.strip_suffix('\n').unwrap_or("").to_string();
Ok(()) Ok(())
} }
@ -393,7 +393,7 @@ impl TTApp {
let task_id = self.tasks.lock().unwrap()[selected].id().unwrap_or_default(); let task_id = self.tasks.lock().unwrap()[selected].id().unwrap_or_default();
let output = Command::new("task").arg(format!("{}", task_id)).output(); let output = Command::new("task").arg(format!("{}", task_id)).output();
if let Ok(output) = output { if let Ok(output) = output {
let data = String::from_utf8_lossy(&*output.stdout); let data = String::from_utf8_lossy(&output.stdout);
let p = Paragraph::new(Text::from(&data[..])).block( let p = Paragraph::new(Text::from(&data[..])).block(
Block::default() Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
@ -673,8 +673,8 @@ impl TTApp {
} }
let output = task.output()?; let output = task.output()?;
let data = String::from_utf8(output.stdout)?; let data = String::from_utf8_lossy(&output.stdout);
let error = String::from_utf8(output.stderr)?; let error = String::from_utf8_lossy(&output.stderr);
if !error.contains("The expression could not be evaluated.") { if !error.contains("The expression could not be evaluated.") {
let imported = import(data.as_bytes())?; let imported = import(data.as_bytes())?;
*(self.tasks.lock().unwrap()) = imported; *(self.tasks.lock().unwrap()) = imported;
@ -851,7 +851,7 @@ impl TTApp {
match output { match output {
Ok(output) => { Ok(output) => {
let data = String::from_utf8(output.stdout).unwrap_or_default(); let data = String::from_utf8_lossy(&output.stdout);
for line in data.split('\n') { for line in data.split('\n') {
if line.starts_with("Virtual tags") { if line.starts_with("Virtual tags") {
let line = line.to_string(); let line = line.to_string();
@ -960,8 +960,8 @@ impl TTApp {
Err(format!( Err(format!(
"`task edit` for task `{}` failed. {}{}", "`task edit` for task `{}` failed. {}{}",
task_id, task_id,
String::from_utf8(output.stdout).unwrap_or_default(), String::from_utf8_lossy(&output.stdout),
String::from_utf8(output.stderr).unwrap_or_default() String::from_utf8_lossy(&output.stderr),
)) ))
} else { } else {
Ok(()) Ok(())

View file

@ -98,7 +98,7 @@ impl Config {
let mut color_collection = HashMap::new(); let mut color_collection = HashMap::new();
let output = Command::new("task").arg("rc.color=off").arg("show").output()?; let output = Command::new("task").arg("rc.color=off").arg("show").output()?;
let data = String::from_utf8(output.stdout).expect("Unable to convert stdout to string"); let data = String::from_utf8_lossy(&output.stdout);
for line in data.split('\n') { for line in data.split('\n') {
if line.starts_with("color.") { if line.starts_with("color.") {
let mut i = line.split(' '); let mut i = line.split(' ');
@ -264,7 +264,7 @@ impl Config {
.output() .output()
.expect("Unable to run `task show`"); .expect("Unable to run `task show`");
let data = String::from_utf8(output.stdout).expect("Unable to convert stdout to string"); let data = String::from_utf8_lossy(&output.stdout);
for line in data.split('\n') { for line in data.split('\n') {
if line.starts_with(config) { if line.starts_with(config) {

View file

@ -88,7 +88,7 @@ impl TaskReportTable {
self.labels = vec![]; self.labels = vec![];
let output = Command::new("task").arg("show").arg("report.next.columns").output()?; let output = Command::new("task").arg("show").arg("report.next.columns").output()?;
let data = String::from_utf8(output.stdout)?; let data = String::from_utf8_lossy(&output.stdout);
for line in data.split('\n') { for line in data.split('\n') {
if line.starts_with("report.next.columns") { if line.starts_with("report.next.columns") {
@ -100,7 +100,7 @@ impl TaskReportTable {
} }
let output = Command::new("task").arg("show").arg("report.next.labels").output()?; let output = Command::new("task").arg("show").arg("report.next.labels").output()?;
let data = String::from_utf8(output.stdout)?; let data = String::from_utf8_lossy(&output.stdout);
for line in data.split('\n') { for line in data.split('\n') {
if line.starts_with("report.next.labels") { if line.starts_with("report.next.labels") {