Skip to content

Commit f78d827

Browse files
Add getSystemErrorName
1 parent a4bd178 commit f78d827

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Node/Errors/SystemError.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
import util from "node:util";
2+
export const getSystemErrorName = (errno) => util.getSystemErrorName(errno);
13
export const getField = (field, err) => err[field];
24
export const getNullableField = (field, err) => err[field] ? err[field] : null;

src/Node/Errors/SystemError.purs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Node.Errors.SystemError
44
, code
55
, dest
66
, errno
7+
, getSystemErrorName
78
, info
89
, message
910
, path
@@ -37,9 +38,14 @@ code = runFn2 getField "code"
3738
dest :: SystemError -> Maybe String
3839
dest = toMaybe <<< runFn2 getNullableField "dest"
3940

41+
-- | Use `getSystemErrorName` to convert Int into a string name
4042
errno :: SystemError -> Int
4143
errno = runFn2 getField "errno"
4244

45+
-- | Returns the string name for a numeric error code that comes from a Node.js API.
46+
-- | The mapping between error codes and error names is platform-dependent.
47+
foreign import getSystemErrorName :: Int -> String
48+
4349
info :: SystemError -> Foreign
4450
info = runFn2 getField "info"
4551

0 commit comments

Comments
 (0)