Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine appendvec sanitize error message to include path #29541

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"));
}
}