Skip to content

Instantly share code, notes, and snippets.

@sk-gachou
Last active April 6, 2023 03:13
Show Gist options
  • Save sk-gachou/2dd253acb1e1663e37119120c2db4768 to your computer and use it in GitHub Desktop.
Save sk-gachou/2dd253acb1e1663e37119120c2db4768 to your computer and use it in GitHub Desktop.
Reproducing ipfs-http-client crash when using searchParams option

How to reproduce

Run IPFS daemon

ipfs daemon

Run command

node index.js

It should crash with this error

node:internal/util:76
  const str = `${val}`;
              ^

TypeError: Cannot convert a Symbol value to a string
    at toUSVString (node:internal/util:76:15)
    at new URLSearchParams (node:internal/url:231:30)
    at toUrlSearchParams (file:///Users/goose/workspace/js-ipfs-reproduce-error/node_modules/ipfs-http-client/src/lib/to-url-search-params.js:42:27)
    at Object.cat (file:///Users/goose/workspace/js-ipfs-reproduce-error/node_modules/ipfs-http-client/src/cat.js:16:21)
    at cat.next (<anonymous>)
    at file:///Users/goose/workspace/js-ipfs-reproduce-error/index.js:8:16
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.14.2
import * as IpfsClient from "ipfs-http-client";
const ipfs = IpfsClient.create({ url: "http://127.0.0.1:8080" });
const searchParams = new URLSearchParams({ offline: "true" });
const stream = ipfs.cat("QmTEzo7FYzUCd5aq7bGKoMLfsbbsebpfARRZd4Znejb25R", {
searchParams,
timeout: 2_000,
});
for await (let chunk of stream) {
console.log("chunk :>> ", chunk);
}
{
"name": "js-ipfs-reproduce-error",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"license": "ISC",
"dependencies": {
"ipfs-http-client": "^60.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment