Error handling and asynchronous behavior in evaluate function
jacobgoh101 opened this issue · 0 comments
-
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: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:
- 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