Skip to content

Commit f90aef7

Browse files
author
Zane Starr
committed
Refactor repo initialization to return boolean
1 parent 4afe130 commit f90aef7

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/index.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ class IpfsRepo {
8181
// check if the repo is already initialized
8282
try {
8383
await this.root.open()
84-
await this._isInitialized()
84+
const initialized = await this._isInitialized()
85+
if (!initialized) {
86+
throw Object.assign(new Error('repo is not initialized yet'),
87+
{
88+
code: ERRORS.ERR_REPO_NOT_INITIALIZED,
89+
path: this.path
90+
})
91+
}
8592
this.lockfile = await this._openLock(this.path)
8693
log('aquired repo.lock')
8794
log('creating datastore')
@@ -149,28 +156,16 @@ class IpfsRepo {
149156
/**
150157
* Check if the repo is already initialized.
151158
* @private
152-
* @returns {Promise<void>}
159+
* @returns {Promise<bool>}
153160
*/
154161
async _isInitialized () {
155162
log('init check')
156-
let res
157-
let config, spec, version
163+
let config, spec
158164
try {
159-
[config, spec, version] = await Promise.all([this.config.exists(), this.spec.exists(), this.version.check(repoVersion)])
160-
res = {
161-
config: config,
162-
spec: spec,
163-
version: version
164-
}
165+
[config, spec] = await Promise.all([this.config.exists(), this.spec.exists(), this.version.check(repoVersion)])
166+
return config && spec
165167
} catch (err) {
166-
if (err && !res.config) {
167-
throw Object.assign(new Error('repo is not initialized yet'),
168-
{
169-
code: ERRORS.ERR_REPO_NOT_INITIALIZED,
170-
path: this.path
171-
})
172-
}
173-
throw err
168+
return false
174169
}
175170
}
176171

0 commit comments

Comments
 (0)