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
Problem description: In the JSONata library, the evaluate function does not properly handle errors when a callback function is used. The error is thrown without being returned to the callback function, causing unhandled errors. It is expected that the error should be returned in the callback function. The problematic code can be found here:
// throw if the expression compiled with syntax errors
if(typeoferrors!=='undefined'){
varerr={
code: 'S0500',
position: 0
};
populateMessage(err);// possible side-effects on `err`
throwerr;
}
if(typeofbindings!=='undefined'){
varexec_env;
// the variable bindings have been passed in - create a frame to hold these
exec_env=createFrame(environment);
for(varvinbindings){
exec_env.bind(v,bindings[v]);
}
}else{
exec_env=environment;
}
// put the input document into the environment as the root object
exec_env.bind('$',input);
// capture the timestamp and put it in the execution environment
// the $now() and $millis() functions will return this value - whenever it is called
timestamp=newDate();
exec_env.timestamp=timestamp;
// if the input is a JSON array, then wrap it in a singleton sequence so it gets treated as a single input
if(Array.isArray(input)&&!isSequence(input)){
input=createSequence(input);
input.outerWrapper=true;
}
varit;
try{
it=awaitevaluate(ast,input,exec_env);
if(typeofcallback==="function"){
callback(null,it);
}
returnit;
}catch(err){
// insert error message into structure
populateMessage(err);// possible side-effects on `err`
throwerr;
}
},
Inconsistent behavior: The documentation and this comment suggests using a callback function to enable asynchronous mode. However, during testing, it seems that the asynchronous function gets evaluated regardless of whether a callback function is used or not.
Reproduction Steps:
Use the evaluate function with a callback function to handle the result asynchronously.
Trigger an error condition that should result in an error being returned.
Observe that the error is not returned through the callback function, but instead thrown directly.
Expected Behavior:
When a callback function is used, the evaluate function should return the error through the callback function instead of throwing it directly. Additionally, the asynchronous behavior should only take effect when a valid callback function is provided.
Environment:
JSONata library version: 2.0.3
Operating System: macOS 13.4.1
Browser or Node.js version: Node v18.16.0
The text was updated successfully, but these errors were encountered:
Problem description: In the JSONata library, the
evaluate
function does not properly handle errors when a callback function is used. The error is thrown without being returned to the callback function, causing unhandled errors. It is expected that the error should be returned in the callback function. The problematic code can be found here:jsonata/src/jsonata.js
Lines 2094 to 2141 in d7790e8
Inconsistent behavior: The documentation and this comment suggests using a callback function to enable asynchronous mode. However, during testing, it seems that the asynchronous function gets evaluated regardless of whether a callback function is used or not.
Reproduction Steps:
evaluate
function with a callback function to handle the result asynchronously.Expected Behavior:
When a callback function is used, the
evaluate
function should return the error through the callback function instead of throwing it directly. Additionally, the asynchronous behavior should only take effect when a valid callback function is provided.Environment:
The text was updated successfully, but these errors were encountered: