Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Browser: Reloading page with static repoName throws error #773

Closed
aphelionz opened this issue Feb 24, 2017 · 7 comments
Closed

Browser: Reloading page with static repoName throws error #773

aphelionz opened this issue Feb 24, 2017 · 7 comments

Comments

@aphelionz
Copy link
Contributor

Steps to reproduce:

Run this code in the browser to connect to a repo with a static name. In this case "pastebin"

const repoName = "pastebin";

let ipfs = new Ipfs({
  repo: repoName,
  EXPERIMENTAL: {
    pubsub: false
  }
});
 
const startApp = (err) => {
  if(err) throw err;
  console.log("good to go")
};

const goOnline = () => ipfs.goOnline(startApp);
const loadIpfs = () => ipfs.load(goOnline);

ipfs.init({ emptyRepo: true, bits: 2048 }, loadIpfs);

Expected Behavior: console should log "good to go" every time
Actual Behavior: the console logs "good to go" the first time, and throws the error the second time

This is related to IndexedDB. It seems ipfs.init doesn't like existing repos.

It also seems that emptyRepo has no effect, as this error occurs when it is true or false. Upon further inspection emptyRepo is used to "seed" the database with the initial blocks.

@dignifiedquire
Copy link
Member

This is somewhat expected, but I agree the api is currently not easy to understand.

  • ipfs.init corresponds ipfs init on the cli, which has the same behaviour, it will error out if a repo already exists in its place. The concept here is, this should only be called once, and on subsequent calls it's not needed anymore.
  • emptyRepo as you wrote, controls if there are some seed files put into the repo, not if something should be overwritten.

What to do:

  • Currently the expectation is that the application using ipfs, handles detection if there is already a repo initialized, and if not to call init
  • There is an internal method ipfs._repo.exists((err, exists) => {}) which can be used to check if a repo was initialized, it might be good to expose this properly and document it.

@aphelionz
Copy link
Contributor Author

Thanks! I will try ipfs._repo.exists and report back.

@aphelionz
Copy link
Contributor Author

@dignifiedquire that worked. How can I help getting it exposed and documented?

@dignifiedquire
Copy link
Member

How about exposing it to the main ipfs object in src/core/index.js, so it can be used like this

ipfs.repoExists(callback)

@daviddias
Copy link
Member

daviddias commented Mar 6, 2017

We kind of mimicked the behaviour of go-ipfs in this one, but I can the value of having a direct call to check for a boolean instead of checking for an error.

There is already a repoExists available at https://github.com/ipfs/js-ipfs/blob/master/src/core/utils.js#L3-L15 that is used by https://github.com/ipfs/js-ipfs/blob/master/src/core/components/repo.js#L11-L24.

I see three ways we can have this done:

  • create a module just to check the existence of the repo
  • expose a function as @dignifiedquire suggested
  • expose the function as ipfs.repo.exists

In reality, you are just checking if there something in that path and not validating its contents, so that is space to improve there as well.

@aphelionz
Copy link
Contributor Author

Thanks @diasdavid

I've started the work here: #776. Let me know which direction I should take it and I'll be happy to finish the work.

@daviddias
Copy link
Member

@aphelionz gave you my feedback there. Will close this issue, let's continue the discussion of this feature there. Thank you for contributing! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants