javascript - How can I instantiate a new SystemError object in Node.js? - Stack Overflow

Looking at Node's documentation, SystemError extends the Error class. However, if you attempt to u

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?

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?

Share Improve this question edited Feb 3, 2020 at 18:46 Austin Davis asked Feb 3, 2020 at 16:25 Austin DavisAustin Davis 1121 silver badge8 bronze badges 1
  • 1 I'm pretty certain that you would need to import it with require('errors') or so, unlike the other errors it's not global. But I guess you shouldn't create SystemErrors yourself anyway. – Bergi Commented Feb 3, 2020 at 17:04
Add a ment  | 

1 Answer 1

Reset to default 7

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/api/errors.html#errors_class_systemerror

In the Github https://github./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./DefinitelyTyped/DefinitelyTyped/search?q=systemError&unscoped_q=systemError

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744889934a4599346.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信