Giter Club home page Giter Club logo

Comments (14)

onury avatar onury commented on May 5, 2024 3

See custom-error-test module.

Extending Error is a decision. It should not be marked as bad-practice altogether. I can only agree that, if you don't need it, you shouldn't complicate things.

But it can be very useful if done right. For example, HttpError and DbError might both throw a message about a "connection loss". In cases like this, best way to inspect the roots of an error might be to check via instanceof. (Especially in a promise chain, where the error thrown jumps all the way down to the catch clause.)

When it comes to errors and debugging; better be specific.

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 5, 2024

@florentulve the example does subclass Error object in JS old fashion style:
//centralized error object that derives from Node’s Error

function appError(name, httpCode, description, isOperational) {
    Error.call(this);
    Error.captureStackTrace(this);
    this.name = name;
};

appError.prototype.__proto__ = Error.prototype;

https://github.com/i0natan/nodebestpractices/blob/master/sections/errorhandling/useonlythebuiltinerror.md

It absolutely makes sense to include some modern subclassing example, would you like to PR your nice example?

Wouldn't the catch clause imply handling Exceptions locally and not in a centralized error handler?

from nodebestpractices.

BrunoScheufler avatar BrunoScheufler commented on May 5, 2024

the custom error as a subclassed version would be awesome but as @i0natan said, if we were to handle errors centralized the catch clause would have to be removed or modified!

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 5, 2024

@BrunoScheufler @florentulve are you up for replacing the example with one that uses modern class inheritance + simple client invoking and catching? not sure whether we should see client calling and catching, at least not a complex client with function one + function two

from nodebestpractices.

BrunoScheufler avatar BrunoScheufler commented on May 5, 2024

What about using the custom Error class MDN provides? The try/catch could be striped out or handled differently.

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 5, 2024

@BrunoScheufler CustomError looks cool, is it supported in Node LTS?

from nodebestpractices.

BrunoScheufler avatar BrunoScheufler commented on May 5, 2024

I have to try that out - I'm using it on a daily basis but I have to check for LTS

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 5, 2024

@BrunoScheufler isn't it duplicated? I believe I saw PR related to this

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 5, 2024

@BrunoScheufler ping

from nodebestpractices.

BrunoScheufler avatar BrunoScheufler commented on May 5, 2024

Do you by any chance have that PR? I think this issue might be older than the PR, but I haven't checked.

from nodebestpractices.

goldbergyoni avatar goldbergyoni commented on May 5, 2024

@onury the provided table within the link is awsome. Must find its way into our error section (if you like to PR it would be great).

We agree that - At the very least, one must have an implementation of an Error object that has a name/code so callee of functions can identify various issues. The exact technique is subject to various preferences?

from nodebestpractices.

stale avatar stale commented on May 5, 2024

Hello there! πŸ‘‹
This issue has gone silent. Eerily silent. ⏳
We currently close issues after 100 days of inactivity. It has been 90 days since the last update here.
If needed, you can keep it open by replying here.
Thanks for being a part of the Node.js Best Practices community! πŸ’š

from nodebestpractices.

onury avatar onury commented on May 5, 2024

@i0natan I currently don't have the time but you can use any content from the repo I mentioned if you're willing to.

from nodebestpractices.

stale avatar stale commented on May 5, 2024

Hello there! πŸ‘‹
This issue has gone silent. Eerily silent. ⏳
We currently close issues after 100 days of inactivity. It has been 90 days since the last update here.
If needed, you can keep it open by replying here.
Thanks for being a part of the Node.js Best Practices community! πŸ’š

from nodebestpractices.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.