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

Commit

Permalink
fix(cli): Tell user to init repo if not initialized when starting daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
victorb committed Nov 29, 2016
1 parent 1a94699 commit fa7e275
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = {
console.log('Initializing daemon...')
httpAPI = new HttpAPI(process.env.IPFS_PATH)
httpAPI.start((err) => {
if (err.code === 'ENOENT') {
console.log('Error: no ipfs repo found in ' + process.env.IPFS_PATH)
console.log('please run: jsipfs init')
process.exit(1)
}
if (err) {
throw err
}
Expand Down
8 changes: 7 additions & 1 deletion src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ exports = module.exports = function HttpApi (repo) {
}

this.ipfs = new IPFS(repo)
const repoPath = this.ipfs.repo.path()

try {
fs.statSync(repoPath)
} catch (err) {
return callback(err)
}

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

this.ipfs.load(() => {
const repoPath = this.ipfs.repo.path()
const apiPath = path.join(repoPath, 'api')

try {
Expand Down
28 changes: 28 additions & 0 deletions test/cli/test-daemon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const clean = require('../utils/clean')
const ipfsCmd = require('../utils/ipfs-exec')

describe('daemon', function () {
let repoPath
let ipfs

beforeEach(() => {
repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8)
ipfs = ipfsCmd(repoPath)
})

afterEach(() => {
clean(repoPath)
})

it('gives error if user hasn\'t run init before', (done) => {
const expectedError = 'no ipfs repo found in ' + repoPath
ipfs('daemon').catch((err) => {
expect(err.stdout).to.have.string(expectedError)
done()
})
})
})

0 comments on commit fa7e275

Please sign in to comment.