Skip to content

Commit

Permalink
Add getSystemErrorName
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Jul 20, 2023
1 parent a4bd178 commit f78d827
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Node/Errors/SystemError.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import util from "node:util";
export const getSystemErrorName = (errno) => util.getSystemErrorName(errno);
export const getField = (field, err) => err[field];
export const getNullableField = (field, err) => err[field] ? err[field] : null;
6 changes: 6 additions & 0 deletions src/Node/Errors/SystemError.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Node.Errors.SystemError
, code
, dest
, errno
, getSystemErrorName
, info
, message
, path
Expand Down Expand Up @@ -37,9 +38,14 @@ code = runFn2 getField "code"
dest :: SystemError -> Maybe String
dest = toMaybe <<< runFn2 getNullableField "dest"

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

-- | Returns the string name for a numeric error code that comes from a Node.js API.
-- | The mapping between error codes and error names is platform-dependent.
foreign import getSystemErrorName :: Int -> String

info :: SystemError -> Foreign
info = runFn2 getField "info"

Expand Down

0 comments on commit f78d827

Please sign in to comment.