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

Commit 237da20

Browse files
authored
Merge pull request #633 from ipfs/deamon-init-msg
fix(cli): Tell user to init repo if not initialized when starting daemon
2 parents 1a94699 + fa7e275 commit 237da20

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-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 {

test/cli/test-daemon.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const expect = require('chai').expect
5+
const clean = require('../utils/clean')
6+
const ipfsCmd = require('../utils/ipfs-exec')
7+
8+
describe('daemon', function () {
9+
let repoPath
10+
let ipfs
11+
12+
beforeEach(() => {
13+
repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8)
14+
ipfs = ipfsCmd(repoPath)
15+
})
16+
17+
afterEach(() => {
18+
clean(repoPath)
19+
})
20+
21+
it('gives error if user hasn\'t run init before', (done) => {
22+
const expectedError = 'no ipfs repo found in ' + repoPath
23+
ipfs('daemon').catch((err) => {
24+
expect(err.stdout).to.have.string(expectedError)
25+
done()
26+
})
27+
})
28+
})

0 commit comments

Comments
 (0)