Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
SwinX committed Mar 23, 2017
1 parent 0d50863 commit bd6a8e2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
8 changes: 7 additions & 1 deletion bin/docpub.js
Expand Up @@ -39,7 +39,13 @@ program.on('--help', () => {

program.parse(process.argv);

const docpub = new Docpub(program);
let docpub;

try {
docpub = new Docpub(program);
} catch (e) {
process.exit(1); // in case docpub failed to construct interface instance, unable to continue
}

docpub
.uploadCategory()
Expand Down
21 changes: 17 additions & 4 deletions lib/docpub.js
Expand Up @@ -31,7 +31,7 @@ module.exports = class Docpub {
logger.setup(opts);

this._path = path.resolve(opts.path);
this._config = new Config(opts.configPath, this._path);
this._config = this._loadConfig(opts);
}

/**
Expand Down Expand Up @@ -63,11 +63,24 @@ module.exports = class Docpub {
);
})
.catch(e => {
logger.error(`Upload failed!`);
logger.error(e.message);
logger.error(e.stack);
this._logError(e);

return Promise.reject(e);
});
}

_loadConfig(opts) {
try {
return new Config(opts.configPath, this._path);
} catch (e) {
this._logError(e);
throw e;
}
}

_logError(error) {
logger.error(`Upload failed!`);
logger.error(error.message);
logger.error(error.stack);
}
};
8 changes: 8 additions & 0 deletions test/unit/docpub.js
Expand Up @@ -90,6 +90,14 @@ describe('Docpub', () => {
path.resolve('path/to/doc/dir')
);
});

it('should throw if failed to create config', () => {
const error = new Error('error');

Config.throws(error);

expect(() => new Docpub({path: 'foo/bar'})).to.throw(error);
});
});

describe('uploadCategory', () => {
Expand Down

0 comments on commit bd6a8e2

Please sign in to comment.