-
Notifications
You must be signed in to change notification settings - Fork 300
findprovs returns object or string #76
Comments
Tried using node-ipfs-api in browser and seems to always return a string of json stream... Not sure how to handle this. Take a look here for quick demo: victorb/webpack-node-ipfs-api-demo@c3dc5e2 |
following the IRC discussion -> We need proper Node.js and Browser tests, testing every API call, so that the interface gets polished (#57), otherwise it will feel that we are always chasing one more little thing. Thank you for catching this @victorbjelkholm. If someone wants to go ahead and bring that, it will be very appreciated :) |
I'm building an application on top IPFS and just ran into this problem. I read a little bit and if I understand correctly this bug will be fixed by solving #87 right? Sorry to bother, just trying to get an estimate for the solution |
@fazo96 right now, this depends on what the API returns, if the IPFS node decides that has enough stuff to stream it, js-ipfs-api will return a stream, otherwise it will return a String, the decision is made on this flag - https://github.com/ipfs/js-ipfs-api/blob/master/src/request-api.js#L63 @whyrusleeping is there any option to choose the mode explicitly? |
I think there should be explicit options so api users can decide how they want to consume the results. |
@dignifiedquire in that case, we should provide both ability to set stream/object in all methods and for individual ones. |
@victorbjelkholm exactly, so that it's predictable, at the moment it's more guessing than anything. |
Is this still a issue with the latest changes? Could you confirm @victorbjelkholm ? |
Sorry, the issue is that some commands return an array and some return a single object depending if run from the browser or from node |
This is still an issue on the latest version as of now. Findprovs returns a string with multiple json documents and there's no easy way to parse it because you would have to cut it when a document finishes and another one starts, I don't think it should be like that. Maybe return an array of strings or a stream where each element is a parsable json? |
@fazo96 are you using IPFS 0.3.9? That sounds like IPFS 0.3.8 (which didn't use ndjson) |
I'm using IPFS 0.3.9 and js-ipfs-api 2.9.0 (just updated it). I'm afraid the problem remains, but I guess I can apply ndjson.parse() myself so it's not a big deal |
The issue is two fold, 1) go-ipfs returns a different format in the browser 2) that format is invalid json, so it has to first be fixed there: ipfs/kubo#1978 |
Turns out this is a bug on our side..We are not properly all headers, resulting in the wrong handling of the response. |
Real problem
|
using the method
ipfs.dht.findprovs
in node environment does not work like one would expect. Using the following code:I get the following output sometimes (which works correctly):
but other times, it returns this (which is neither streamable or valid json)
Originally open issue ipfs/kubo#1851 on go-ipfs but seems to be a bug in this library.
The text was updated successfully, but these errors were encountered: