Error on jq.run filter escapes the promise chain and throws to the user
See original GitHub issueDescription
Invalid JQ Expression causes NestJS to completely crash. Attemp to catch exception is ignored by node.
Test Source
@Controller('/hello')
export class AppController {
@Get('testjq')
async testJq(): Promise<void> {
await jq
.run(
'invalid expression',
{ test: 'object' },
{ input: 'json', output: 'compact' },
)
.then((res) => console.log(res))
.catch((_err) => console.error('Trying to catch error'));
}
}
Call URL Using HTTPie
$ http http://localhost:3000/hello/testjq
http: error: ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)) while doing a GET request to URL: http://localhost:3000/hello/testjq
Error Message & Stack Trace
[Nest] 7974 - 06/29/2022, 2:52:49 AM LOG [NestApplication] Nest application successfully started +2ms
Error: write EPIPE
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:795:11)
at Socket._write (node:net:807:8)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at Socket.Writable.write (node:internal/streams/writable:334:10)
at /home/user/projects/nestjsproject/node_modules/node-jq/lib/exec.js:25:27
at new Promise (<anonymous>)
at Object.exec [as default] (/home/user/projects/nestjsproject/node_modules/node-jq/lib/exec.js:15:12)
Environment
AlmaLinux 8 running inside WSL2 on Windows 11 (build 22000.778). Server using NestJS running on top of ExpressJS.
nodejs version:
Node.js v16.14.0
linux 5.10.102.1-microsoft-standard-WSL2
npm version:
8.3.1
node-jq version:
"version": "2.3.3",
NestJS info:
_ _ _ ___ _____ _____ _ _____
| \ | | | | |_ |/ ___|/ __ \| | |_ _|
| \| | ___ ___ | |_ | |\ `--. | / \/| | | |
| . ` | / _ \/ __|| __| | | `--. \| | | | | |
| |\ || __/\__ \| |_ /\__/ //\__/ /| \__/\| |_____| |_
\_| \_/ \___||___/ \__|\____/ \____/ \____/\_____/\___/
[System Information]
OS Version : Linux 5.10
NodeJS Version : v16.14.0
NPM Version : 8.3.1
[Nest CLI]
Nest CLI Version : 8.2.8
[Nest Platform Information]
platform-express version : 8.4.7
schematics version : 8.0.11
passport version : 8.2.2
testing version : 8.4.7
common version : 8.4.7
config version : 2.1.0
axios version : 0.0.8
core version : 8.4.7
jwt version : 8.0.1
cli version : 8.2.8
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Issues · sanack/node-jq - GitHub
Contribute to sanack/node-jq development by creating an account on GitHub. ... Error on jq.run filter escapes the promise chain and throws to the...
Read more >Break promise chain and call a function based on the step in ...
I've accomplished everything except what I'm trying to do. How do I write promises so that I can call a function on rejection,...
Read more >jQuery API Documentation
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax ......
Read more >jq error, usage message when piping - Unix Stack Exchange
When you invoke as jq dada1.json , the first non-flag argument (not-starting with a - ) is parsed as the filter, as @glenn-jackman...
Read more >pact-js
did you follow an example on how to use pact? rgshah781988. 2018-05-09 07:26 ... Throwing errors or rejecting promises is much more idiomatic...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m seeing the same crash with any invalid filter. E.g.: https://replit.com/@samarths-msft/try-node-jq#index.js. In our scenario, filter is supplied by ExpressJS app user. It can be invalid due to user error. If filter is invalid, we want to catch the error and return “invalid filter error” to the user. However, due to invalid filter, the ExpressJS app itself is crashing.
After trying to replicate the issue, I found the cause of your problems. Published a template to open bugs: https://replit.com/@DavidSancho/try-node-jq?v=1. You can try to replicate your issue there if you want.
If the “filter” contains a space, it will break node. So, if the expression is invalid, it will crash due a unhandledRejection in node. Making any script to explore if you don’t handle that.