Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions thunder/strato_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ where
}
}

fn preview_for_log(text: &str) -> &str {
const MAX_PREVIEW_BYTES: usize = 300;
if text.len() <= MAX_PREVIEW_BYTES {
return text;
}
// Truncating at a fixed byte offset can split a multi-byte UTF-8
// character (user names in these responses are not ASCII), which
// would panic; back up to the nearest char boundary instead.
let mut end = MAX_PREVIEW_BYTES;
while !text.is_char_boundary(end) {
end -= 1;
}
&text[..end]
}

#[derive(Debug, Deserialize)]
struct UserProfile {
name: String,
Expand Down Expand Up @@ -154,7 +169,7 @@ impl StratoClient {
"Failed to parse following list response for {}: {}. Response preview: {}",
user_id,
e,
&text[..text.len().min(300)]
preview_for_log(&text)
);
Err(anyhow!(e))
}
Expand Down Expand Up @@ -224,7 +239,7 @@ impl StratoClient {
"Failed to parse user metadata response for {}: {}. Response preview: {}",
user_id,
e,
&text[..text.len().min(300)]
preview_for_log(&text)
);
Ok(None)
}
Expand Down