Skip to content

Commit

Permalink
core: fix not showing syntax error
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Sep 27, 2023
1 parent 79d0445 commit 48208dd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
52 changes: 28 additions & 24 deletions src/bundles/c/core/run-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <inttypes.h>

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,
Expand Down Expand Up @@ -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,
};

6 changes: 5 additions & 1 deletion src/js/run-main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/syntax-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo bar
16 changes: 16 additions & 0 deletions tests/test-syntax-error.js
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit 48208dd

Please sign in to comment.