Skip to content

Commit af7797c

Browse files
committed
f Improve list error handling
1 parent 68b2fa5 commit af7797c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,27 @@ impl KVStore for FilesystemStore {
281281
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
282282
}
283283

284-
if let Some(relative_path) = p.strip_prefix(&prefixed_dest).ok()
285-
.and_then(|p| p.to_str()) {
286-
if relative_path.chars().all(|c| c.is_ascii() && !c.is_control()) {
287-
keys.push(relative_path.to_string())
284+
match p.strip_prefix(&prefixed_dest) {
285+
Ok(stripped_path) => {
286+
if let Some(relative_path) = stripped_path.to_str() {
287+
if relative_path.chars().all(|c| c.is_ascii() && !c.is_control()) {
288+
keys.push(relative_path.to_string())
289+
}
290+
} else {
291+
debug_assert!(false, "Failed to list keys of namespace {}: file path is not valid UTF-8",
292+
PrintableString(namespace));
293+
let msg = format!("Failed to list keys of namespace {}: file path is not valid UTF-8",
294+
PrintableString(namespace));
295+
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
288296
}
297+
}
298+
Err(e) => {
299+
debug_assert!(false, "Failed to list keys of namespace {}: {}",
300+
PrintableString(namespace), e);
301+
let msg = format!("Failed to list keys of namespace {}: {}",
302+
PrintableString(namespace), e);
303+
return Err(std::io::Error::new(std::io::ErrorKind::Other, msg));
304+
}
289305
}
290306
}
291307

0 commit comments

Comments
 (0)