Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Aug 6, 2024
1 parent 985d359 commit 1254911
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn ceil_char_boundary(value: &str, index: usize) -> usize {
.map_or(upper_bound, |pos| pos + index)
}

pub fn truncate_large_string<F: fmt::Write>(f: &mut F, val: Cow<'_, str>) -> std::fmt::Result {
pub fn write_truncated_to_50_bytes<F: fmt::Write>(f: &mut F, val: Cow<'_, str>) -> std::fmt::Result {
if val.len() > 50 {
write!(
f,
Expand Down
2 changes: 1 addition & 1 deletion src/errors/validation_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl PyLineError {
let input_value = self.input_value.bind(py);
let input_str = safe_repr(input_value);
write!(output, ", input_value=")?;
super::truncate_large_string(&mut output, input_str.to_cow())?;
super::write_truncated_to_50_bytes(&mut output, input_str.to_cow())?;

if let Ok(type_) = input_value.get_type().qualname() {
write!(output, ", input_type={type_}")?;
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ use validators::ValBytesMode;
#[macro_use]
mod py_gc;

pub mod errors;

mod argument_markers;
mod build_tools;
mod definitions;
mod errors;
mod input;
mod lookup_key;
mod recursion_guard;
Expand Down
11 changes: 4 additions & 7 deletions src/serializers/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,12 @@ impl CollectWarnings {
let input_str = safe_repr(value);
let mut value_str = String::with_capacity(100);
value_str.push_str("with value `");
match crate::errors::truncate_large_string(&mut value_str, input_str.to_cow()) {
Err(_) => value_str.clear(),
Ok(()) => {
value_str.push_str("` ");
}
};
crate::errors::write_truncated_to_50_bytes(&mut value_str, input_str.to_cow())
.expect("Writing to a `String` failed");
value_str.push_str("`");

self.add_warning(format!(
"Expected `{field_type}` but got `{type_name}` {value_str}- serialized value may not be as expected"
"Expected `{field_type}` but got `{type_name}` {value_str} - serialized value may not be as expected"
));
}
}
Expand Down

0 comments on commit 1254911

Please sign in to comment.