Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch only takes a string, not a UrlWithLegacySupport #74

Closed
roderik opened this issue Nov 5, 2020 · 5 comments · Fixed by #75
Closed

Fetch only takes a string, not a UrlWithLegacySupport #74

roderik opened this issue Nov 5, 2020 · 5 comments · Fixed by #75
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@roderik
Copy link
Contributor

roderik commented Nov 5, 2020

In https://github.com/ipfs/js-ipfs-utils/blob/master/src/http.js#L134-L159 the call to make is put into iso-url which returns a UrlWithLegacySupport.

A few lines lower, this is passed into fetch.

This throws the following error:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received an instance of URLWithLegacySupport
    at validateString (internal/validators.js:124:11)
    at Url.parse (url.js:159:3)
    at urlParse (url.js:154:13)
    at new Request (/home/coder/project/node_modules/node-fetch/lib/request.js:27:16)
    at /home/coder/project/node_modules/node-fetch/index.js:51:17
    at new Promise (<anonymous>)
    at new Fetch (/home/coder/project/node_modules/node-fetch/index.js:49:9)
    at Fetch (/home/coder/project/node_modules/node-fetch/index.js:37:10)
    at Client.fetch (/home/coder/project/node_modules/ipfs-utils/src/http.js:148:36)
    at Client.fetch (/home/coder/project/node_modules/ipfs-http-client/src/lib/core.js:162:20)
    at Client.post (/home/coder/project/node_modules/ipfs-utils/src/http.js:190:17)
    at addAll (/home/coder/project/node_modules/ipfs-http-client/src/add-all.js:22:27)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at last (/home/coder/project/node_modules/it-last/index.js:15:20)
    at Object.add (/home/coder/project/node_modules/ipfs-http-client/src/add.js:18:14)

Changing the fetch call to the following fixes this, but I'm wondering how this code has been in use in this repo for a long time and suddenly it starts erroring out for me.

    const response = await timeout(fetch(url.href, {

I tried Node 12 and 14, no difference there. (I was hoping url.parse was changed)

@roderik roderik added the need/triage Needs initial labeling and prioritization label Nov 5, 2020
@welcome
Copy link

welcome bot commented Nov 5, 2020

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review.
In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment.
Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@roderik
Copy link
Contributor Author

roderik commented Nov 5, 2020

[email protected] works, 48.0.0 does not, so I suspect ipfs/js-ipfs#3351

@roderik
Copy link
Contributor Author

roderik commented Nov 5, 2020

Do I need to cross-post in the other repo, because it does not seem to be a utils issue?

@achingbrain
Copy link
Member

I can't replicate this, and we have lots of tests that run with the HTTP client, but you are quite right, the fetch docs say the first argument should be a string and not a URL.

Could you create a PR to this module that just calls toString() on the url being passed to fetch? That should do it.

@achingbrain achingbrain added kind/bug A bug in existing code (including security flaws) and removed need/triage Needs initial labeling and prioritization labels Nov 5, 2020
@roderik
Copy link
Contributor Author

roderik commented Nov 9, 2020

Done

achingbrain pushed a commit that referenced this issue Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants