Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 73x 1x 1x 1x 1x 1x 73x 73x 21x 21x 21x 21x 21x 21x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 21x 21x 21x 21x 1x 1x 1x 1x 73x 73x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 11x 73x 73x 1x 1x 1x 1x 1x 5x 5x 5x | /**
* Error Fingerprint Generation
*
* Creates stable fingerprints for error grouping.
* Normalizes variable parts (line numbers, hashes, IDs) to group similar errors.
*/
import crypto from 'crypto';
export interface FingerprintInput {
message?: string;
stack?: string;
category?: string;
url?: string;
}
/**
* Generate a stable fingerprint for an error
* Uses SHA-256 for better collision resistance than MD5
*
* @param error - Error data to fingerprint
* @returns 32-character hex fingerprint
*/
export function generateErrorFingerprint(error: FingerprintInput): string {
const normalizedStack = normalizeStackTrace(error.stack || '');
const pathPattern = extractPathPattern(error.url || '');
// Create composite fingerprint from normalized components
const components = [
error.category || 'unknown',
normalizeMessage(error.message || ''),
normalizedStack,
pathPattern,
].join('|');
return crypto.createHash('sha256').update(components).digest('hex').slice(0, 32);
}
/**
* Normalize error message by removing variable parts
*/
function normalizeMessage(message: string): string {
return (
message
.slice(0, 200) // Take first 200 chars
// Remove UUIDs
.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, 'UUID')
// Remove numbers that look like IDs
.replace(/\b\d{5,}\b/g, 'ID')
// Remove timestamps
.replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/g, 'TIMESTAMP')
// Remove quoted strings with numbers
.replace(/"[^"]*\d+[^"]*"/g, '"VALUE"')
);
}
/**
* Normalize stack trace to group similar errors
* Removes line numbers, column numbers, and hash suffixes
*/
function normalizeStackTrace(stack: string): string {
if (!stack) return '';
return (
stack
.split('\n')
.slice(0, 5) // Take first 5 lines only
.map((line) => {
return (
line
// Remove line:column numbers
.replace(/:\d+:\d+/g, ':X:X')
// Remove webpack/build hashes
.replace(/\/[a-f0-9]{8,}/gi, '/HASH')
// Remove query strings
.replace(/\?[^\s)]+/g, '')
// Remove chunk numbers
.replace(/chunk-[A-Z0-9]+/gi, 'chunk-X')
// Normalize anonymous functions
.replace(/<anonymous>/g, '<anon>')
);
})
.join('\n')
);
}
/**
* Extract path pattern from URL, replacing dynamic segments
*/
function extractPathPattern(url: string): string {
if (!url) return '';
try {
const parsed = new URL(url);
return (
parsed.pathname
// Replace numeric IDs with placeholder
.replace(/\/\d+/g, '/:id')
// Replace UUIDs with placeholder
.replace(
/\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
'/:uuid'
)
// Replace slugs that look like IDs
.replace(/\/[a-f0-9]{24}/gi, '/:objectId')
);
} catch {
// If URL parsing fails, try to extract path-like string
const pathMatch = url.match(/\/[^\s?#]*/);
return pathMatch ? pathMatch[0].replace(/\/\d+/g, '/:id') : '';
}
}
/**
* Create a short hash for display purposes
* Not for grouping, just for human-readable IDs
*/
export function createShortHash(input: string): string {
return crypto.createHash('md5').update(input).digest('hex').slice(0, 8);
}
|