Collapse a message to a grouping key. Session ids, turn numbers, hashes and paths all vary between occurrences of the same underlying failure. Normalizing them is what turns 546 separate lines into one actionable row.
(message: &str)
| 552 | /// of the same underlying failure. Normalizing them is what turns 546 |
| 553 | /// separate lines into one actionable row. |
| 554 | fn error_signature(message: &str) -> String { |
| 555 | let chars: Vec<char> = message.chars().collect(); |
| 556 | let mut out = String::with_capacity(chars.len()); |
| 557 | let mut i = 0; |
| 558 | |
| 559 | while i < chars.len() { |
| 560 | let c = chars[i]; |
| 561 | if c.is_ascii_digit() { |
| 562 | while i < chars.len() && chars[i].is_ascii_digit() { |
| 563 | i += 1; |
| 564 | } |
| 565 | out.push('N'); |
| 566 | } else if c.is_ascii_alphanumeric() || c == '_' { |
| 567 | let start = i; |
| 568 | while i < chars.len() && (chars[i].is_ascii_alphanumeric() || chars[i] == '_') { |
| 569 | i += 1; |
| 570 | } |
| 571 | let word: String = chars[start..i].iter().collect(); |
| 572 | out.push_str(&normalize_token(&word)); |
| 573 | } else { |
| 574 | out.push(c); |
| 575 | i += 1; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | out.split_whitespace().collect::<Vec<_>>().join(" ") |
| 580 | } |
| 581 | |
| 582 | /// Map a bare word to a placeholder when it looks like an identifier. |
| 583 | /// |