tldr-node-client: tldr is showing a debug message when a page was not found

When I run tldr on a command which could not be found, I get the following output:

✔ Page not found. Updating cache...
✔ Creating index...
Error: Page not found.
If you want to contribute it, feel free to send a pull request to: https://github.com/tldr-pages/tldr
    at /usr/lib/node_modules/tldr/lib/tldr.js:147:17

Does the last line have any purpose? It’s always the same and not really useful. (tldr version 3.3.7)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (14 by maintainers)

Most upvoted comments

It works!!! 🎉 I wrote message(), instead of message. I’ll open a PR

I just copy-pasted stuff from the internet 😅

Exactly as you told: lib/tldrerror.js:

module.exports.TldrError = TldrError

class TldrError extends Error {
    constructor(message) {
        super(message);
    }
}

In lib/tldr.js:

const TldrError = require('./tldrerror');

In tldr

const TldrError = require('../lib/tldrerror');

I tried importing it with and without the curly braces.

Btw, thanks for explaining all that to me, you probably would be a lot faster if you did it yourself 😅

I just copy-pasted stuff from the internet 😅

You did that by the book 😂 https://nitter.cc/ThePracticalDev/status/705825638851149824

How about

class TldrError extends Error {
    constructor(message) {
        super(message);
    }
}

and

p.catch((err) => {
    if(err instanceof TldrError) {
        console.error(err.message());
    } else {
        console.error(err);
    }
    process.exitCode = 1;
  });

?

No problem, I don’t mind in the least.

  1. It’s more conventional (at least, it also may be required 🤷🏻) to export things after you declare them, so in tldrerror.js put the module.exports line below the class definition

  2. Since you’re creating a whole new file for TldrError (which is the right way to do it), and you’re probably not going to put anything else than the class in the file, you can directly export the class instead of exporting an object that contains the class, so write module.exports = TldrError; instead

That should theoretically work.

I’d like to, but i hardly know any javascript.