cosmo
cosmo copied to clipboard
"wgc subgraph list' only logs 8192 characters
Component(s)
cli
Component version
0.57.3
wgc version
0.57.3
What happened?
We are using the wgc subgraph list command in one of our internal tools. We haven't had any issues until we tried to run the tool on the MacBook of my colleague. Since we are parsing the raw JSON output of npx wgc subgraph list -n ${namespace} -r we always got the error Unexpected token in JSON at position 8192.. We dug deeper and it seems the bug lies within the asynchronous behavior of console.log in these 2 lines of code. We inserted a setTimeout and also tested it with fs.writeSync(1, JSON.stringify(xxx)) and this way it correctly outputs the whole JSON before exiting the process. We can only assume that the reason for this bug is the async behavior of console.log for large outputs and the immediate process.exit().
If you have a suggested way of fixing this issue, perhaps using fs.writeSync(), I'd be willing to create a PR.
Environment information
Environment
Laptop model: MacBook Pro M3 FN4CG9RWH1 OS: Sonoma 14.5 Package Manager: npm
WunderGraph commits fully to Open Source and we want to make sure that we can help you as fast as possible. The roadmap is driven by our customers and we have to prioritize issues that are important to them. You can influence the priority by becoming a customer. Please contact us here.
Hi @alumpe thanks for the report. We would be happy to review a PR. Would you like to share what company you represent?
Hey @StarpTech, I represent gastromatic, I believe some of my colleagues already communicated closely with you in the past. If I find time this week, I will make a PR. I thought about creating a small wrapper function a la logToConsole(text) => {} that can be used in every place where syncronous logging is important.
Hi @alumpe, could you provide a reproducible example? I can't test the asynchronous behaviour. I generated a huge JSON object with https://json-generator.com/, printed it and parsed it with jq. It never failed. I see no reason why the cli should behave differently in this case. I'm fine with your solution but before we need a way to test it.
const a = ...
console.log(JSON.stringify(a));
process.exit(0);
node test.js | jq
I'm on a Mac as well.
Hi @alumpe,
is this still relevant for you? I tried to reproduce the issue even by fetching and pushing data through console.log and piping it's outputs. Unfortunately no chance.
Unexpected token in JSON at position 8192.
Sounds to me, that either the json is broken already before or that something happens on the network, it's just an assumption. You might want to update all components and try again, maybe something was fixed in the meantime.
If it is still an issue, could you please, tell me with what file size you end up when running: wgc subgraph list -n ${namespace} -r > raw.json?
Hi @alumpe,
We've not heard back from you, so I'm going to close this. You can respond at any time, and we can reopen.
Thanks,
The WunderGraph Team