From 2514c79d33e62551d9b4980b0d3a8abecebc476b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 27 Sep 2023 08:15:43 +0200 Subject: [PATCH] core: fix not showing syntax error --- src/bundles/c/core/run-main.c | 52 +++++++++++++++++++---------------- src/js/run-main/index.js | 6 +++- tests/helpers/syntax-error.js | 1 + tests/test-syntax-error.js | 16 +++++++++++ 4 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 tests/helpers/syntax-error.js create mode 100644 tests/test-syntax-error.js diff --git a/src/bundles/c/core/run-main.c b/src/bundles/c/core/run-main.c index e852f896..56ec996c 100644 --- a/src/bundles/c/core/run-main.c +++ b/src/bundles/c/core/run-main.c @@ -2,9 +2,9 @@ #include -const uint32_t tjs__run_main_size = 20583; +const uint32_t tjs__run_main_size = 20614; -const uint8_t tjs__run_main[20583] = { +const uint8_t tjs__run_main[20614] = { 0x02, 0xc0, 0x03, 0x16, 0x72, 0x75, 0x6e, 0x2d, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x6a, 0x73, 0x16, 0x74, 0x6a, 0x73, 0x3a, 0x67, 0x65, 0x74, 0x6f, @@ -2556,27 +2556,31 @@ const uint8_t tjs__run_main[20583] = { 0x0e, 0x38, 0x1e, 0x01, 0x00, 0x00, 0x42, 0x36, 0x01, 0x00, 0x00, 0xb6, 0x24, 0x01, 0x00, 0x29, 0xbc, 0x03, 0x2f, 0x00, 0x0e, 0x02, 0x06, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, 0x31, - 0x00, 0xe2, 0x03, 0x0a, 0x00, 0xca, 0x03, 0x06, - 0x09, 0x6c, 0x18, 0x00, 0x00, 0x00, 0xdd, 0x41, - 0x31, 0x01, 0x00, 0x00, 0x42, 0x9a, 0x02, 0x00, - 0x00, 0x65, 0x01, 0x00, 0x24, 0x01, 0x00, 0x0e, - 0x0e, 0x29, 0x0e, 0x6c, 0x15, 0x00, 0x00, 0x00, - 0x38, 0x1e, 0x01, 0x00, 0x00, 0x42, 0x36, 0x01, - 0x00, 0x00, 0xb6, 0x24, 0x01, 0x00, 0x0e, 0x0e, - 0x29, 0x2f, 0xbc, 0x03, 0x2f, 0x00, 0x0e, 0x43, - 0x06, 0x01, 0xee, 0x03, 0x02, 0x01, 0x02, 0x07, - 0x00, 0x00, 0x48, 0x03, 0xc2, 0x03, 0x00, 0x01, - 0x00, 0xc4, 0x03, 0x00, 0x01, 0x00, 0xc6, 0x03, - 0x01, 0x00, 0x20, 0x61, 0x00, 0x00, 0x38, 0x95, - 0x00, 0x00, 0x00, 0x42, 0x9b, 0x02, 0x00, 0x00, - 0xd1, 0xbd, 0x0a, 0x24, 0x02, 0x00, 0xc9, 0x38, - 0x95, 0x00, 0x00, 0x00, 0x42, 0x15, 0x02, 0x00, - 0x00, 0x62, 0x00, 0x00, 0x24, 0x01, 0x00, 0xea, - 0x1f, 0x38, 0x94, 0x00, 0x00, 0x00, 0x11, 0x04, - 0x9c, 0x02, 0x00, 0x00, 0x42, 0x5c, 0x00, 0x00, - 0x00, 0xd1, 0x04, 0x9d, 0x02, 0x00, 0x00, 0xd2, - 0x24, 0x03, 0x00, 0x21, 0x01, 0x00, 0x2f, 0x62, - 0x00, 0x00, 0x28, 0xbc, 0x03, 0x2f, 0x00, + 0x00, 0x00, 0x01, 0x00, 0x04, 0x02, 0x00, 0x4b, + 0x01, 0xac, 0x08, 0x03, 0x00, 0x03, 0xe2, 0x03, + 0x0a, 0x00, 0xca, 0x03, 0x06, 0x09, 0x6c, 0x18, + 0x00, 0x00, 0x00, 0xdd, 0x41, 0x31, 0x01, 0x00, + 0x00, 0x42, 0x9a, 0x02, 0x00, 0x00, 0x65, 0x01, + 0x00, 0x24, 0x01, 0x00, 0x0e, 0x0e, 0x29, 0xc9, + 0x6c, 0x2f, 0x00, 0x00, 0x00, 0xc5, 0x38, 0xcb, + 0x00, 0x00, 0x00, 0xa7, 0x11, 0xea, 0x10, 0x0e, + 0x38, 0x2c, 0x01, 0x00, 0x00, 0x42, 0xb6, 0x01, + 0x00, 0x00, 0xc5, 0x24, 0x01, 0x00, 0x0e, 0x38, + 0x1e, 0x01, 0x00, 0x00, 0x42, 0x36, 0x01, 0x00, + 0x00, 0xb6, 0x24, 0x01, 0x00, 0x0e, 0x0e, 0x29, + 0x2f, 0xbc, 0x03, 0x2f, 0x00, 0x0e, 0x43, 0x06, + 0x01, 0xee, 0x03, 0x02, 0x01, 0x02, 0x07, 0x00, + 0x00, 0x48, 0x03, 0xc2, 0x03, 0x00, 0x01, 0x00, + 0xc4, 0x03, 0x00, 0x01, 0x00, 0xc6, 0x03, 0x01, + 0x00, 0x20, 0x61, 0x00, 0x00, 0x38, 0x95, 0x00, + 0x00, 0x00, 0x42, 0x9b, 0x02, 0x00, 0x00, 0xd1, + 0xbd, 0x0a, 0x24, 0x02, 0x00, 0xc9, 0x38, 0x95, + 0x00, 0x00, 0x00, 0x42, 0x15, 0x02, 0x00, 0x00, + 0x62, 0x00, 0x00, 0x24, 0x01, 0x00, 0xea, 0x1f, + 0x38, 0x94, 0x00, 0x00, 0x00, 0x11, 0x04, 0x9c, + 0x02, 0x00, 0x00, 0x42, 0x5c, 0x00, 0x00, 0x00, + 0xd1, 0x04, 0x9d, 0x02, 0x00, 0x00, 0xd2, 0x24, + 0x03, 0x00, 0x21, 0x01, 0x00, 0x2f, 0x62, 0x00, + 0x00, 0x28, 0xbc, 0x03, 0x2f, 0x00, }; diff --git a/src/js/run-main/index.js b/src/js/run-main/index.js index 8ceb17f4..27323700 100644 --- a/src/js/run-main/index.js +++ b/src/js/run-main/index.js @@ -127,7 +127,11 @@ if (options.help) { globalThis.queueMicrotask(() => { try { internals.core.evalFile(filename); - } catch (_) { + } catch (e) { + if (e instanceof SyntaxError) { + console.error(e); + } + tjs.exit(1); } }); diff --git a/tests/helpers/syntax-error.js b/tests/helpers/syntax-error.js new file mode 100644 index 00000000..d675fa44 --- /dev/null +++ b/tests/helpers/syntax-error.js @@ -0,0 +1 @@ +foo bar diff --git a/tests/test-syntax-error.js b/tests/test-syntax-error.js new file mode 100644 index 00000000..3652cc50 --- /dev/null +++ b/tests/test-syntax-error.js @@ -0,0 +1,16 @@ +import assert from 'tjs:assert'; +import path from 'tjs:path'; + + +const args = [ + tjs.exepath, + 'run', + path.join(import.meta.dirname, 'helpers', 'syntax-error.js') +]; +const proc = tjs.spawn(args, { stdout: 'pipe', stderr: 'ignore' }); +const buf = new Uint8Array(4096); +const nread = await proc.stdout.read(buf); +const stderrStr = new TextDecoder().decode(buf.subarray(0, nread)); +const status = await proc.wait(); +assert.ok(stderrStr.match(/SyntaxError/) !== null, 'dumps to stderr'); +assert.ok(status.exit_status === 1 && status.term_signal === null, 'succeeded');