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?
-
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 createSystemError
s yourself anyway. – Bergi Commented Feb 3, 2020 at 17:04
1 Answer
Reset to default 7I 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条)