Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix missing render path error #354

Merged
merged 6 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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: 4 additions & 1 deletion bin/tldr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pkg = require('../package');
const Tldr = require('../lib/tldr');
const config = require('../lib/config');
const platform = require('../lib/platform');
const { TldrError } = require('../lib/errors');
const { TldrError, MissingRenderPathError } = require('../lib/errors');

program
.version(pkg.version, '-v, --version', 'Display version')
Expand Down Expand Up @@ -108,6 +108,9 @@ if (program.list) {
return tldr.updateIndex();
});
} else if (program.render) {
if (typeof program.render !== 'string') {
throw new MissingRenderPathError();
}
p = tldr.render(program.render);
} else if (program.search) {
program.args.unshift(program.search);
Expand Down
15 changes: 13 additions & 2 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,27 @@ 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(trim`
Option --render needs an argument.
`);
this.name = 'MissingRenderPathError';
this.code = 4;
}
}

module.exports = {
TldrError,
EmptyCacheError,
MissingPageError
MissingPageError,
MissingRenderPathError
};

function trim(strings, ...values) {
Expand Down