| 52 | // If fixups also fail, we deliberately let the error propagate — a crash loop is |
| 53 | // preferable to silently skipping (and acknowledging) unprocessable changes. |
| 54 | override parse(buffer: Buffer): any { |
| 55 | const raw = buffer.toString() |
| 56 | try { |
| 57 | return JSON.parse(raw) |
| 58 | } catch (e) { |
| 59 | const fixed = raw |
| 60 | .replace(/"change":\[,+/g, '"change":[') // leading commas: [,{ → [{ |
| 61 | .replace(/,+]/g, ']') // trailing commas: ,] → ] |
| 62 | .replace(/,,+/g, ',') // consecutive commas: ,, → , |
| 63 | const result = JSON.parse(fixed) |
| 64 | console.warn( |
| 65 | `SafeWal2JsonPlugin: fixed malformed wal2json output (eulerto/wal2json#266). ` + |
| 66 | `Original error: ${e}. Payload sample: ${raw.slice(0, 200)}` |
| 67 | ) |
| 68 | return result |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | const ONE_MINUTE = 60 * 1000 |