Skip to content

Commit

Permalink
Refine appendvec sanitize error message to include path (solana-labs#…
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 authored and gnapoli23 committed Jan 10, 2023
1 parent d768862 commit db26895
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions runtime/src/append_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,17 @@ impl AppendVec {
}

pub fn new_from_file<P: AsRef<Path>>(path: P, current_len: usize) -> io::Result<(Self, usize)> {
let new = Self::new_from_file_unchecked(path, current_len)?;
let new = Self::new_from_file_unchecked(&path, current_len)?;

let (sanitized, num_accounts) = new.sanitize_layout_and_length();
if !sanitized {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"incorrect layout/length/data",
));
// This info show the failing accountvec file path. It helps debugging
// the appendvec data corrupution issues related to recycling.
let err_msg = format!(
"incorrect layout/length/data in the appendvec at path {}",
path.as_ref().display()
);
return Err(std::io::Error::new(std::io::ErrorKind::Other, err_msg));
}

Ok((new, num_accounts))
Expand Down Expand Up @@ -1153,7 +1156,7 @@ pub mod tests {
}

let result = AppendVec::new_from_file(path, accounts_len);
assert_matches!(result, Err(ref message) if message.to_string() == *"incorrect layout/length/data");
assert_matches!(result, Err(ref message) if message.to_string().starts_with("incorrect layout/length/data"));
}

#[test]
Expand Down Expand Up @@ -1181,7 +1184,7 @@ pub mod tests {
let accounts_len = av.len();
drop(av);
let result = AppendVec::new_from_file(path, accounts_len);
assert_matches!(result, Err(ref message) if message.to_string() == *"incorrect layout/length/data");
assert_matches!(result, Err(ref message) if message.to_string().starts_with("incorrect layout/length/data"));
}

#[test]
Expand All @@ -1207,7 +1210,7 @@ pub mod tests {
let accounts_len = av.len();
drop(av);
let result = AppendVec::new_from_file(path, accounts_len);
assert_matches!(result, Err(ref message) if message.to_string() == *"incorrect layout/length/data");
assert_matches!(result, Err(ref message) if message.to_string().starts_with("incorrect layout/length/data"));
}

#[test]
Expand Down Expand Up @@ -1269,6 +1272,6 @@ pub mod tests {
let accounts_len = av.len();
drop(av);
let result = AppendVec::new_from_file(path, accounts_len);
assert_matches!(result, Err(ref message) if message.to_string() == *"incorrect layout/length/data");
assert_matches!(result, Err(ref message) if message.to_string().starts_with("incorrect layout/length/data"));
}
}

0 comments on commit db26895

Please sign in to comment.