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

fix(cli): Tell user to init repo if not initialized when starting daemon #633

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
})
})