0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-29 11:12:33 +01:00

fix(err): limit context line length (#26397)

This commit is contained in:
Oliver Browne 2024-11-25 19:55:14 +02:00 committed by GitHub
parent c0db78bee8
commit 94c2b0a456
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -108,8 +108,8 @@ pub struct Context {
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct ContextLine {
pub number: u32,
pub line: String,
number: u32,
line: String,
}
impl Frame {
@ -155,9 +155,16 @@ impl Frame {
impl ContextLine {
pub fn new(number: u32, line: impl ToString) -> Self {
let line = line.to_string();
// We limit context line length to 300 chars
let mut constrained: String = line.to_string().chars().take(300).collect();
if line.len() > constrained.len() {
constrained.push_str("...✂️");
}
Self {
number,
line: line.to_string(),
line: constrained,
}
}
}