forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts.patch
More file actions
55 lines (47 loc) · 1.35 KB
/
Copy pathindex.ts.patch
File metadata and controls
55 lines (47 loc) · 1.35 KB
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
/**
* E2B CLI — E2B_ERROR_HANDLER injection template
*
* Target: packages/cli/src/index.ts
* Changes: wrap main() + listen unhandledRejection
*/
// ---- Add at top of file (after existing imports) ----
import { spawn } from 'node:child_process'
// ---- Add helper function (before main()) ----
/** Fire-and-forget external handler for unhandled errors. */
function runExternalErrorHandler(reason: string): void {
const handler = process.env.E2B_ERROR_HANDLER?.trim()
if (!handler) return
try {
const payload = {
schemaVersion: 1,
reason,
timestamp: new Date().toISOString(),
pid: process.pid,
}
const child = spawn(handler, [JSON.stringify(payload)], {
env: { PATH: process.env.PATH },
stdio: 'ignore',
detached: true,
shell: false,
})
child.on('error', () => {})
child.unref()
} catch {}
}
// ---- Wrap main() with error handler ----
async function main() {
await prog.parseAsync()
await updateCheck
}
// Replace bare main() call with:
main().catch((err) => {
runExternalErrorHandler('unhandled_rejection')
console.error(String(err?.stack || err?.message || err))
process.exit(1)
})
// Add at bottom of file:
process.on('uncaughtException', (err) => {
runExternalErrorHandler('uncaught_exception')
console.error(String(err?.stack || err?.message || err))
process.exit(1)
})