@@ -4,35 +4,52 @@ const SERIALIZE_ERROR = require('./serialize-error')
44
55module . exports = snippet => `
66 ;(async () => {
7- const args = JSON.parse(process.argv[2])
7+ try {
8+ const args = JSON.parse(process.argv[2])
89
9- /* https://github.com/Kikobeats/null-prototype-object */
10- const logging = new (/* @__PURE__ */ (() => { let e = function(){}; return e.prototype = Object.create(null), Object.freeze(e.prototype), e })());
10+ /* https://github.com/Kikobeats/null-prototype-object */
11+ const logging = new (/* @__PURE__ */ (() => { let e = function(){}; return e.prototype = Object.create(null), Object.freeze(e.prototype), e })());
1112
12- for (const method of ['log', 'info', 'debug', 'warn', 'error']) {
13- console[method] = function (...args) {
14- logging[method] === undefined ? logging[method] = [args] : logging[method].push(args)
13+ for (const method of ['log', 'info', 'debug', 'warn', 'error']) {
14+ console[method] = function (...args) {
15+ logging[method] === undefined ? logging[method] = [args] : logging[method].push(args)
16+ }
1517 }
16- }
1718
18- ;await (async (send) => {
19- process.stdout.write = function () {}
20- let value
21- let isFulfilled
19+ ;await (async (send) => {
20+ process.stdout.write = function () {}
21+ let value
22+ let isFulfilled
2223
23- try {
24- value = await (${ snippet . toString ( ) } )(...args)
25- isFulfilled = true
26- } catch (error) {
27- value = ${ SERIALIZE_ERROR } (error)
28- isFulfilled = false
29- } finally {
30- send(JSON.stringify({
31- isFulfilled,
32- logging,
33- value,
34- profiling: { memory: process.memoryUsage().rss }
35- }))
36- }
37- })(process.stdout.write.bind(process.stdout))
38- })()`
24+ try {
25+ value = await (${ snippet . toString ( ) } )(...args)
26+ isFulfilled = true
27+ } catch (error) {
28+ value = ${ SERIALIZE_ERROR } (error)
29+ isFulfilled = false
30+ } finally {
31+ send(JSON.stringify({
32+ isFulfilled,
33+ logging,
34+ value,
35+ profiling: { memory: process.memoryUsage().rss }
36+ }))
37+ }
38+ })(process.stdout.write.bind(process.stdout))
39+ } catch (error) {
40+ process.stdout.write(JSON.stringify({
41+ isFulfilled: false,
42+ logging: {},
43+ value: ${ SERIALIZE_ERROR } (error),
44+ profiling: { memory: process.memoryUsage().rss }
45+ }))
46+ }
47+ })().catch(err => {
48+ process.stdout.write(JSON.stringify({
49+ isFulfilled: false,
50+ logging: {},
51+ value: ${ SERIALIZE_ERROR } (err),
52+ profiling: { memory: process.memoryUsage().rss }
53+ }))
54+ process.exitCode = 1
55+ })`
0 commit comments