Skip to content

error callback is undefined #1314

Closed

Description

@dennisdupont

Using v1.7.2 in a node app.

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.

jsfiddle was not working for node so I created a similar version at runkit:
https://runkit.com/60677da356be380013a31abc/60677da318e85d001c2257fc

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.

Activity

  1. dennisdupont commented on Apr 2, 2021

    @dennisdupont
    Author

    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.

  2. mathiasrw commented on May 25, 2021

    @mathiasrw
    Member

    Thank you for reporting this.

  3. WarrenMartin commented on Apr 1, 2026

    @WarrenMartin

    Hi, just checking on this issue, is it still present in the latest version?

  4. pratyushsinghal7 commented on Jul 24, 2026

    @pratyushsinghal7
    Contributor

    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.

  5. added a commit that references this issue on Oct 20, 2026
    94ce1ad
  6. mathiasrw commented on Oct 21, 2026

    @mathiasrw
    Member

    Fix released as part of v4.21.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions