From 78201346b9d422c00e563a573f7d07d264f4c9aa Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Sat, 17 Sep 2022 14:41:35 +0300 Subject: [PATCH] Catch at least *some* errors out of ajv. Doesn't catch all of them, because even though AJV's strict mode is documented to default to true, it also has a strictTypes setting which defaults to 'log', meaning it will spew some messages to stderr (which currently bowtie always marks as an uncaught error). Unclear yet precisely what to tweak. --- implementations/js-ajv/bowtie_ajv.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/implementations/js-ajv/bowtie_ajv.js b/implementations/js-ajv/bowtie_ajv.js index 8944dbe56..2acbf9d9f 100644 --- a/implementations/js-ajv/bowtie_ajv.js +++ b/implementations/js-ajv/bowtie_ajv.js @@ -63,14 +63,22 @@ const cmds = { run: (args) => { console.assert(started, "Not started!"); - const testCase = args.case; - const validate = ajv.compile(testCase.schema); - return { - seq: args.seq, - results: testCase.tests.map((test) => ({ - valid: validate(test.instance), - })), - }; + try { + const testCase = args.case; + const validate = ajv.compile(testCase.schema); + return { + seq: args.seq, + results: testCase.tests.map((test) => ({ + valid: validate(test.instance), + })), + }; + } catch (e) { + return { + errored: true, + seq: args.seq, + context: { error: e.toString() }, + }; + } }, stop: (_) => {