This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments