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

Commit 5365f46

Browse files
committed
Check if repo is initialized before starting daemon
1 parent 1a94699 commit 5365f46

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/cli/commands/daemon.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ module.exports = {
1616
console.log('Initializing daemon...')
1717
httpAPI = new HttpAPI(process.env.IPFS_PATH)
1818
httpAPI.start((err) => {
19+
if (err.code === 'ENOENT') {
20+
console.log('Error: no ipfs repo found in ' + process.env.IPFS_PATH)
21+
console.log('please run: jsipfs init')
22+
process.exit(1)
23+
}
1924
if (err) {
2025
throw err
2126
}

src/http-api/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,17 @@ exports = module.exports = function HttpApi (repo) {
2525
}
2626

2727
this.ipfs = new IPFS(repo)
28+
const repoPath = this.ipfs.repo.path()
29+
30+
try {
31+
fs.statSync(repoPath)
32+
} catch (err) {
33+
return callback(err)
34+
}
2835

2936
console.log('Starting at %s', this.ipfs.repo.path())
3037

3138
this.ipfs.load(() => {
32-
const repoPath = this.ipfs.repo.path()
3339
const apiPath = path.join(repoPath, 'api')
3440

3541
try {

0 commit comments

Comments
 (0)