diff --git a/lib/errors.js b/lib/errors.js index 617f1e8..882c4e5 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -29,16 +29,26 @@ class MissingPageError extends TldrError { Page not found. If you want to contribute it, feel free to send a pull request to: ${repo} `); - this.name = 'MissingPageErrror'; + this.name = 'MissingPageError'; // eslint-disable-next-line no-magic-numbers this.code = 3; } } +class MissingRenderPathError extends TldrError { + constructor() { + super('Option --render needs an argument.'); + this.name = 'MissingRenderPathError'; + // eslint-disable-next-line no-magic-numbers + this.code = 4; + } +} + module.exports = { TldrError, EmptyCacheError, - MissingPageError + MissingPageError, + MissingRenderPathError }; function trim(strings, ...values) { diff --git a/lib/tldr.js b/lib/tldr.js index 3c0ffcb..823e0fc 100644 --- a/lib/tldr.js +++ b/lib/tldr.js @@ -4,7 +4,7 @@ const sample = require('lodash/sample'); const fs = require('fs-extra'); const ms = require('ms'); const ora = require('ora'); -const { EmptyCacheError, MissingPageError } = require('./errors'); +const { EmptyCacheError, MissingPageError, MissingRenderPathError } = require('./errors'); const Cache = require('./cache'); const search = require('./search'); const platform = require('./platform'); @@ -73,6 +73,9 @@ class Tldr { } render(file) { + if (typeof file !== 'string') { + throw new MissingRenderPathError(); + } return fs.readFile(file, 'utf8') .then((content) => { // Getting the shortindex first to populate the shortindex var