You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Was testing a select from a non-existing JSON file (shamelessly stolen from the multiple JSON file wiki example). alasql(['SELECT * FROM JSON("a.json")']) .then(function(res) { var a = res[0]; }).catch(function(err) { console.log(error: ${err}); }) ;
Expected behavior is to catch the error. Instead I get a process-ending unhandled exception.
FYI: Different cause, but another unhandled exception occurs on a JSON.parse error, although one could argue that if the file exists it ought to expected to contain valid JSON. Still, a try catch is in order when parsing IMO.
Looking at the code for loadFile, the last parameter is an error callback. However, it does not seem that the JSON from function (nor the other text from functions) pass in that error handler.
I've created a mocha test for this by adding another it() call to test157:
it('7. Load JSON data from missing file', async function (done) {
alasql.options.errorlog = true;
await assert.rejects(
async () => {
alasql('select * from json("' + __dirname + '/test157missing.json")', [], function (res, err) {
assert.ok(!!err);
assert.ok(!res);
done();
});
});
});
Let me know if that is an acceptable test case or if there is a better way.
Obviously there is a simple workaround to check for the file first, so this is not critical. But I may take this as an opportunity to explore your codebase and it helps me get used to your build/test procedures.
I reproduced this on current develop: a missing JSON file still terminates the process with TypeError: error is not a function instead of rejecting the lazy promise or reporting the error through the query callback. The JSON source's load call currently leaves its error handler outside the loadFile() argument list. I'm preparing a focused fix with regression coverage for both missing files and malformed JSON.
Activity
dennisdupont commentedon Apr 2, 2021
I've created a mocha test for this by adding another it() call to test157:
Let me know if that is an acceptable test case or if there is a better way.
Obviously there is a simple workaround to check for the file first, so this is not critical. But I may take this as an opportunity to explore your codebase and it helps me get used to your build/test procedures.
mathiasrw commentedon May 25, 2021
Thank you for reporting this.
WarrenMartin commentedon Apr 1, 2026
Hi, just checking on this issue, is it still present in the latest version?
pratyushsinghal7 commentedon Jul 24, 2026
I reproduced this on current
develop: a missing JSON file still terminates the process withTypeError: error is not a functioninstead of rejecting the lazy promise or reporting the error through the query callback. The JSON source's load call currently leaves its error handler outside theloadFile()argument list. I'm preparing a focused fix with regression coverage for both missing files and malformed JSON.Fix JSON file error handling to close AlaSQL#1314 (AlaSQL#2513)
mathiasrw commentedon Oct 21, 2026
Fix released as part of v4.21.0