fix: address PR #144 code review feedback
Addresses all concerns raised by Copilot and Codex reviewers: **Type Safety (Copilot #1)**: - Remove dynamic property access `logger[logLevel]` - Use explicit if/else with proper type checking **Visibility (Codex #1)**: - Non-retry errors (protobuf, parsing) always log as ERROR - Remove warn downgrade for unexpected errors **Defensive Coding (Copilot #3)**: - Use `String(originalError?.message ?? originalError)` - Prevents crashes on undefined/null message property **Scope Creep (Codex #2)**: - Add stack trace validation to console.log override - Only suppress logs originating from libsignal module - Prevents affecting unrelated application logs **Logic Clarity (Copilot #2)**: - Clarify that onRetry hooks handle intermediate logging - Maintain clear distinction between retry vs non-retry errors https://claude.ai/code/session_01SoNUGBEWbJwWWws3F2fuzh
This commit is contained in:
+22
-15
@@ -30,22 +30,29 @@ console.log = function(...args: unknown[]) {
|
||||
if (args.length > 0 && typeof args[0] === 'string') {
|
||||
const msg = args[0]
|
||||
|
||||
// Suppress session lifecycle dumps (cryptographic details on every encrypt/decrypt)
|
||||
if (msg.startsWith('Closing session')) {
|
||||
return
|
||||
}
|
||||
// Check if this log comes from libsignal by examining the call stack
|
||||
// This prevents suppressing unrelated logs from other modules
|
||||
const stack = new Error().stack || ''
|
||||
const isFromLibsignal = stack.includes('libsignal') || stack.includes('session_cipher')
|
||||
|
||||
// Suppress transient decryption errors that are auto-recovered by retry logic
|
||||
// These flood logs during normal operation when sessions are being re-established
|
||||
// Final failures are still logged via our structured logger (see decode-wa-message.ts)
|
||||
if (
|
||||
msg.includes('Session error') ||
|
||||
msg.includes('Bad MAC') ||
|
||||
msg.includes('MessageCounterError') ||
|
||||
msg.includes('Key used already or never filled') ||
|
||||
msg.includes('Failed to decrypt message with any known session')
|
||||
) {
|
||||
return // suppress - our retry system handles these gracefully
|
||||
if (isFromLibsignal) {
|
||||
// Suppress session lifecycle dumps (cryptographic details on every encrypt/decrypt)
|
||||
if (msg.startsWith('Closing session')) {
|
||||
return
|
||||
}
|
||||
|
||||
// Suppress transient decryption errors that are auto-recovered by retry logic
|
||||
// These flood logs during normal operation when sessions are being re-established
|
||||
// Final failures are still logged via our structured logger (see decode-wa-message.ts)
|
||||
if (
|
||||
msg.includes('Session error') ||
|
||||
msg.includes('Bad MAC') ||
|
||||
msg.includes('MessageCounterError') ||
|
||||
msg.includes('Key used already or never filled') ||
|
||||
msg.includes('Failed to decrypt message with any known session')
|
||||
) {
|
||||
return // suppress - our retry system handles these gracefully
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user