Skip to content

Commit b4690b6

Browse files
committed
sh: handle errors properly
1 parent 2bee62c commit b4690b6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sh/src/wordexp/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,18 @@ pub fn expand_word(
229229
if files.is_empty() {
230230
result.push(pattern.into())
231231
} else {
232-
// TODO: handle error
233-
result.extend(files.into_iter().map(|s| s.into_string().unwrap()))
232+
result.reserve(files.len());
233+
for file in files {
234+
match file.into_string() {
235+
Ok(string) => result.push(string),
236+
Err(os_string) => {
237+
return Err(CommandExecutionError::ExpansionError(format!(
238+
"{} contains invalid utf8",
239+
os_string.to_string_lossy()
240+
)))
241+
}
242+
}
243+
}
234244
}
235245
}
236246
}

0 commit comments

Comments
 (0)