3.0.1 • Published 7 months ago

@jfabello/system-errors v3.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Node.js Custom System Error Classes

License: MIT

A Node.js module that maps common POSIX system error codes into custom system error classes.

This module helps developers handle POSIX system errors with meaningful and descriptive error messages, enhancing the debugging and error-handling processes.

Table of Contents

Installation

You can install this module via npm:

npm install @jfabello/system-errors

Usage

After installation, import the module and use the createErrorFromSystemErrorCode() method or the predefined custom system error classes in your application:

import { errors as systemErrors } from "@jfabello/system-errors";

try {
	// Some code that might throw a POSIX system error
} catch (error) {
	if ("code" in error) {
		throw systemErrors.createErrorFromSystemErrorCode(error.code);
	} else {
		throw new systemErrors.errors.ERROR_UNKNOWN();
	}
}

Creating Errors Based on System Error Codes

This module provides a createErrorFromSystemErrorCode() method, which dynamically creates a custom system error object based on the POSIX system error code:

import { errors as systemErrors } from "@jfabello/system-errors";

const error = systemErrors.createErrorFromSystemErrorCode("EACCES");
console.log(error.message); // Output: The operation does not have enough permissions.

This method takes a string as its only argument. It returns an instance of the custom system error class that corresponds to the POSIX system error code passed in the string, or an instance of ERROR_UNKNOWN if the string can't be matched to a particular POSIX system error code.

Custom System Error Classes

The module also provides predefined custom system error classes that can be used directly in your code. These classes can be accessed via the errors object. Each class represents a specific POSIX system error and has a descriptive message associated with it:

import { errors as systemErrors } from "@jfabello/system-errors";

const error = new systemErrors.errors.ERROR_NO_ACCESS();
console.log(error.message); // Output: The operation does not have enough permissions.

POSIX System Errors Mapped

POSIX ErrorError ClassError Message
E2BIGERROR_ARGUMENT_LIST_TOO_LONGThe list of arguments is longer than expected
EACCESERROR_NO_ACCESSThe operation does not have enough permissions
EADDRINUSEERROR_ADDRESS_IN_USEThe network address is already in use
EADDRNOTAVAILERROR_ADDRESS_NOT_AVAILABLEThe network address is currently unavailable for use
EAFNOSUPPORTERROR_ADDRESS_FAMILY_NOT_SUPPORTEDThe network address family is not supported
EAGAINERROR_NO_DATA_TRY_AGAIN_LATERThere is no data available. Try again later
EALREADYERROR_SOCKET_PENDING_CONNECTION_IN_PROGRESSThe socket already has a pending connection in progress
EBADFERROR_FILE_DESCRIPTOR_NOT_VALIDFile descriptor is not valid
EBADMSGERROR_INVALID_DATA_MESSAGEInvalid data message
EBUSYERROR_DEVICE_OR_RESOURCE_BUSYDevice or resource is busy
ECANCELEDERROR_OPERATION_CANCELLEDThe operation was canceled
ECHILDERROR_NO_CHILD_PROCESSESThere are no child processes
ECONNABORTEDERROR_NETWORK_CONNECTION_ABORTEDThe network connection has been aborted
ECONNREFUSEDERROR_NETWORK_CONNECTION_REFUSEDThe network connection has been refused
ECONNRESETERROR_NETWORK_CONNECTION_RESETThe network connection has been reset
EDEADLKERROR_RESOURCE_DEADLOCK_AVOIDEDA resource deadlock has been avoided
EDESTADDRREQERROR_DESTINATION_ADDRESS_REQUIREDA destination address is required
EDOMERROR_ARGUMENT_OUT_OF_DOMAINAn argument is out of the domain of the function
EDQUOTERROR_DISK_QUOTA_EXCEEDEDThe disk quota has been exceeded
EEXISTERROR_FILE_EXISTSThe file already exists
EFAULTERROR_INVALID_POINTER_ADDRESSInvalid pointer address
EFBIGERROR_FILE_TOO_LARGEThe file is too large
EHOSTUNREACHERROR_HOST_UNREACHABLEThe host is unreachable
EIDRMERROR_IDENTIFIER_REMOVEDThe identifier has been removed
EILSEQERROR_ILLEGAL_BYTE_SEQUENCEIllegal byte sequence
EINPROGRESSERROR_OPERATION_ALREADY_IN_PROGRESSAn operation is already in progress
EINTRERROR_FUNCTION_CALL_INTERRUPTEDA function call was interrupted
EINVALERROR_INVALID_ARGUMENTAn invalid argument was provided
EIOERROR_UNSPECIFIED_IO_ERRORUnspecified I/O error
EISCONNERROR_SOCKET_CONNECTEDThe socket is connected
EISDIRERROR_PATH_IS_A_DIRECTORYThe path is a directory
ELOOPERROR_TOO_MANY_SYMLINKS_LEVELSToo many levels of symbolic links in a path
EMFILEERROR_TOO_MANY_OPEN_FILESToo many open files
EMLINKERROR_TOO_MANY_LINKS_TO_FILEToo many hard links to the file
EMSGSIZEERROR_MESSAGE_TOO_LONGThe provided message is too long
EMULTIHOPERROR_MULTIHOP_ATTEMPTEDA multihop was attempted
ENAMETOOLONGERROR_FILENAME_TOO_LONGThe filename is too long
ENETDOWNERROR_NETWORK_IS_DOWNThe network is down
ENETRESETERROR_CONNECTION_ABORTED_BY_NETWORKThe connection has been aborted by the network
ENETUNREACHERROR_NETWORK_UNREACHABLEThe network is unreachable
ENFILEERROR_TOO_MANY_OPEN_FILESToo many open files in the system
ENOBUFSERROR_NO_BUFFER_SPACE_AVAILABLENo buffer space is available
ENODATAERROR_NO_MESSAGE_AVAILABLE_ON_STREAMNo message available on the stream head read queue
ENODEVERROR_NO_SUCH_DEVICEThere is no such device
ENOENTERROR_NO_SUCH_FILE_OR_DIRECTORYNo such file or directory
ENOEXECERROR_EXEC_FORMATExec format error
ENOLCKERROR_NO_LOCKS_AVAILABLENo locks available
ENOLINKERROR_LINK_SEVEREDA link has been severed
ENOMEMERROR_NOT_ENOUGH_SPACENot enough space
ENOMSGERROR_NO_MESSAGE_OF_DESIRED_TYPENo message of the desired type
ENOPROTOOPTERROR_PROTOCOL_NOT_AVAILABLEA given protocol is not available
ENOSPCERROR_NO_SPACE_ON_DEVICENo space available on the device
ENOSRERROR_NO_STREAM_RESOURCES_AVAILABLENo stream resources available
ENOSTRERROR_RESOURCE_NOT_A_STREAMThe resource is not a stream
ENOSYSERROR_FUNCTION_NOT_IMPLEMENTEDFunction has not been implemented
ENOTCONNERROR_SOCKET_NOT_CONNECTEDThe socket is not connected
ENOTDIRERROR_NOT_A_DIRECTORYThe path is not a directory
ENOTEMPTYERROR_DIRECTORY_NOT_EMPTYThe directory is not empty
ENOTFOUNDERROR_HOSTNAME_NOT_FOUNDThe host name was not found
ENOTSOCKERROR_NOT_A_SOCKETThe given item is not a socket
ENOTSUPERROR_OPERATION_NOT_SUPPORTEDA given operation is not supported
ENOTTYERROR_INAPPROPRIATE_IO_CONTROL_OPERATIONInappropriate I/O control operation
ENXIOERROR_NO_SUCH_DEVICE_OR_ADDRESSNo such device or address
EOPNOTSUPPERROR_OPERATION_NOT_SUPPORTED_ON_SOCKETAn operation is not supported on the socket
EOVERFLOWERROR_VALUE_TOO_LARGEValue too large to be stored in data type
EPERMERROR_OPERATION_NOT_PERMITTEDThe operation is not permitted
EPIPEERROR_BROKEN_PIPEBroken pipe
EPROTOERROR_PROTOCOL_ERRORProtocol error
EPROTONOSUPPORTERROR_PROTOCOL_NOT_SUPPORTEDProtocol is not supported
EPROTOTYPEERROR_WRONG_PROTOCOL_TYPE_FOR_SOCKETWrong type of protocol for a socket
ERANGEERROR_RESULT_TOO_LARGEResult is too large
EROFSERROR_READ_ONLY_FILE_SYSTEMThe file system is read-only
ESPIPEERROR_INVALID_SEEK_OPERATIONInvalid seek operation
ESRCHERROR_NO_SUCH_PROCESSNo such process
ESTALEERROR_STALE_FILE_HANDLEThe file handle is stale
ETIMEERROR_TIMER_EXPIREDThe timer expired
ETIMEDOUTERROR_CONNECTION_TIMEOUTThe connection timed out
ETXTBSYERROR_TEXT_FILE_BUSYText file is busy
EWOULDBLOCKERROR_OPERATION_WOULD_BLOCKThe operation would block
EXDEVERROR_IMPROPER_LINKImproper link

Contributing

Unfortunately, we are not able to accept contributions at this time.

If you find a bug in the code, please open an issue.

Thank you for your understanding.

License

This project is licensed under the MIT License. See the LICENSE file for details.

3.0.1

7 months ago

3.0.0

7 months ago

2.0.1

7 months ago

2.0.0

7 months ago

1.0.0

12 months ago