javascriptnode.jstypescriptruntime-errorsystem-error

How can I instantiate a new SystemError object in Node.js?


Looking at Node's documentation, SystemError extends the Error class. However, if you attempt to use SystemError directly, Node will throw a ReferenceError saying that SystemError is undefined.

Clearly, according to the docs, it is possible to encounter an instance of SystemError, but it seems impossible to recreate such an error in the usual way (e.g. throw new SystemError(args)).

I would like to test some code which is designed to interact with the specified SystemError API as detailed in the docs, but I have no idea how to recreate a SystemError. Is this even possible?


Solution

  • I think that node.js doesn't put SystemError available in order to avoid anyone (npm packages) to use it. So a SystemError is really a SystemError and not something else.

    If you want to test it, generate the error : Try to read a file that doesn't exist for example.

    An other soluce would be to recreate a lookalike error because you know every property of it. But it's a workaround actually.

    https://nodejs.org/api/errors.html#errors_class_systemerror

    In the Github https://github.com/DefinitelyTyped/DefinitelyTyped I couldn't find any interface declaration of SystemError.

    Except custom implementations made by node-fetch, voximplant-websdk and alexa-sdk.

    https://github.com/DefinitelyTyped/DefinitelyTyped/search?q=systemError&unscoped_q=systemError