mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

Error functions

Data Structures

struct  _mbed_error_ctx
 mbed_error_ctx struct More...

Typedefs

typedef int mbed_error_status_t
 mbed_error_status_t description
typedef enum _mbed_error_type_t mbed_error_type_t
 mbed_error_type_t definition
typedef enum _mbed_module_type mbed_module_type_t
 mbed_module_type_t definition
typedef enum _mbed_error_code mbed_error_code_t
 mbed_error_code_t definition
typedef struct _mbed_error_ctx mbed_error_ctx
 mbed_error_ctx struct
typedef void(* mbed_error_hook_t )(const mbed_error_ctx *error_ctx)
 Callback/Error hook function prototype.
typedef int mbed_error_status_t
 mbed_error_status_t description
typedef enum _mbed_error_type_t mbed_error_type_t
 mbed_error_type_t definition
typedef enum _mbed_module_type mbed_module_type_t
 mbed_module_type_t definition
typedef enum _mbed_error_code mbed_error_code_t
 mbed_error_code_t definition
typedef struct _mbed_error_ctx mbed_error_ctx
 mbed_error_ctx struct
typedef void(* mbed_error_hook_t )(const mbed_error_ctx *error_ctx)
 Callback/Error hook function prototype.

Enumerations

enum  _mbed_error_type_t
 

mbed_error_type_t definition

More...
enum  _mbed_module_type
 

mbed_module_type_t definition

More...
enum  _mbed_error_code
 

mbed_error_code_t definition

More...
enum  _mbed_error_type_t
 

mbed_error_type_t definition

More...
enum  _mbed_module_type
 

mbed_module_type_t definition

More...
enum  _mbed_error_code
 

mbed_error_code_t definition

More...

Functions

MBED_NORETURN void error (const char *format,...) MBED_PRINTF(1
 To generate a fatal compile-time error, you can use the pre-processor error directive.
void mbed_error_reboot_callback (mbed_error_ctx *error_context)
 Callback function for reporting error context during boot up.
mbed_error_status_t mbed_error_initialize (void)
 Initialize error handling system, this is called by the mbed-os boot sequence.
mbed_error_status_t mbed_get_reboot_error_info (mbed_error_ctx *error_info)
 Call this function to retrieve the error context after a fatal error which triggered a system reboot.
mbed_error_status_t mbed_reset_reboot_error_info (void)
 Calling this function resets the current reboot context captured by the system(stored in special crash data RAM region).
mbed_error_status_t mbed_reset_reboot_count (void)
 Calling this function resets the current reboot count stored as part of error context captured in special crash data RAM region.
mbed_error_status_t mbed_warning (mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
 Call this function to set a system error/warning.
mbed_error_status_t mbed_get_first_error (void)
 Returns the first system error reported.
mbed_error_status_t mbed_get_last_error (void)
 Returns the most recent system error reported.
int mbed_get_error_count (void)
 Returns the number of system errors reported after boot.
MBED_NORETURN mbed_error_status_t mbed_error (mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
 Call this function to set a fatal system error and halt the system.
mbed_error_status_t mbed_set_error_hook (mbed_error_hook_t custom_error_hook)
 Registers an application defined error callback with the error handling system.
mbed_error_status_t mbed_get_first_error_info (mbed_error_ctx *error_info)
 Reads the first error context information captured.
mbed_error_status_t mbed_get_last_error_info (mbed_error_ctx *error_info)
 Reads the last error context information captured.
mbed_error_status_t mbed_clear_all_errors (void)
 Clears the last error, first error, error count and all entries in the error history.
mbed_error_status_t mbed_make_error (mbed_error_type_t error_type, mbed_module_type_t module, mbed_error_code_t error_code)
 Generates a mbed_error_status_t value based on passed in values for type, module and error code.
int mbed_get_error_hist_count (void)
 Returns the current number of entries in the error history, if there has been more than max number of errors logged the number returned will be max depth of error history.
mbed_error_status_t mbed_get_error_hist_info (int index, mbed_error_ctx *error_info)
 Reads the error context information for a specific error from error history, specified by the index.
mbed_error_status_t mbed_save_error_hist (const char *path)
 Saves the error history information to a file.

Typedef Documentation

mbed_error_code_t definition

mbed_error_code_t enumeration defines the Error codes and Error status values for MBED_MODULE_UNKNOWN.
It defines all of POSIX Error Codes/Statuses and Mbed System Error Codes/Statuses.

Note:
POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This effectively defines the following values:
ERROR_CODE_EPERM = EPERM
ERROR_EPERM = -EPERM

POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This macro defines the following values:
ERROR_CODE_EPERM = MBED_POSIX_ERROR_BASE+EPERM
ERROR_EPERM = -(MBED_POSIX_ERROR_BASE+EPERM)
Its effectively equivalent to:
ERROR_CODE_EPERM = 1
ERROR_EPERM = -1
All POSIX error codes currently supported by MbedOS(defined in mbed_retarget.h) are defined using the MBED_DEFINE_POSIX_ERROR macro.

Below are the POSIX error codes and the description:

    EPERM                      1        Operation not permitted
    ENOENT                     2        No such file or directory
    ESRCH                      3        No such process
    EINTR                      4        Interrupted system call
    EIO                        5        I/O error
    ENXIO                      6        No such device or address
    E2BIG                      7        Argument list too long
    ENOEXEC                    8        Exec format error
    EBADF                      9        Bad file number
    ECHILD                     10       No child processes
    EAGAIN                     11       Try again
    ENOMEM                     12       Out of memory
    EACCES                     13       Permission denied
    EFAULT                     14       Bad address
    ENOTBLK                    15       Block device required
    EBUSY                      16       Device or resource busy
    EEXIST                     17       File exists
    EXDEV                      18       Cross-device link
    ENODEV                     19       No such device
    ENOTDIR                    20       Not a directory
    EISDIR                     21       Is a directory
    EINVAL                     22       Invalid argument
    ENFILE                     23       File table overflow
    EMFILE                     24       Too many open files
    ENOTTY                     25       Not a typewriter
    ETXTBSY                    26       Text file busy
    EFBIG                      27       File too large
    ENOSPC                     28       No space left on device
    ESPIPE                     29       Illegal seek
    EROFS                      30       Read-only file system
    EMLINK                     31       Too many links
    EPIPE                      32       Broken pipe
    EDOM                       33       Math argument out of domain of func
    ERANGE                     34       Math result not representable
    EDEADLK                    35       Resource deadlock would occur
    ENAMETOOLONG               36       File name too long
    ENOLCK                     37       No record locks available
    ENOSYS                     38       Function not implemented
    ENOTEMPTY                  39       Directory not empty
    ELOOP                      40       Too many symbolic links encountered
    EWOULDBLOCK                EAGAIN   Operation would block
    ENOMSG                     42       No message of desired type
    EIDRM                      43       Identifier removed
    ECHRNG                     44       Channel number out of range
    EL2NSYNC                   45       Level 2 not synchronized
    EL3HLT                     46       Level 3 halted
    EL3RST                     47       Level 3 reset
    ELNRNG                     48       Link number out of range
    EUNATCH                    49       Protocol driver not attached
    ENOCSI                     50       No CSI structure available
    EL2HLT                     51       Level 2 halted
    EBADE                      52       Invalid exchange
    EBADR                      53       Invalid request descriptor
    EXFULL                     54       Exchange full
    ENOANO                     55       No anode
    EBADRQC                    56       Invalid request code
    EBADSLT                    57       Invalid slot
    EDEADLOCK                  EDEADLK  Resource deadlock would occur
    EBFONT                     59       Bad font file format
    ENOSTR                     60       Device not a stream
    ENODATA                    61       No data available
    ETIME                      62       Timer expired
    ENOSR                      63       Out of streams resources
    ENONET                     64       Machine is not on the network
    ENOPKG                     65       Package not installed
    EREMOTE                    66       Object is remote
    ENOLINK                    67       Link has been severed
    EADV                       68       Advertise error
    ESRMNT                     69       Srmount error
    ECOMM                      70       Communication error on send
    EPROTO                     71       Protocol error
    EMULTIHOP                  72       Multihop attempted
    EDOTDOT                    73       RFS specific error
    EBADMSG                    74       Not a data message
    EOVERFLOW                  75       Value too large for defined data type
    ENOTUNIQ                   76       Name not unique on network
    EBADFD                     77       File descriptor in bad state
    EREMCHG                    78       Remote address changed
    ELIBACC                    79       Can not access a needed shared library
    ELIBBAD                    80       Accessing a corrupted shared library
    ELIBSCN                    81       .lib section in a.out corrupted
    ELIBMAX                    82       Attempting to link in too many shared libraries
    ELIBEXEC                   83       Cannot exec a shared library directly
    EILSEQ                     84       Illegal byte sequence
    ERESTART                   85       Interrupted system call should be restarted
    ESTRPIPE                   86       Streams pipe error
    EUSERS                     87       Too many users
    ENOTSOCK                   88       Socket operation on non-socket
    EDESTADDRREQ               89       Destination address required
    EMSGSIZE                   90       Message too long
    EPROTOTYPE                 91       Protocol wrong type for socket
    ENOPROTOOPT                92       Protocol not available
    EPROTONOSUPPORT            93       Protocol not supported
    ESOCKTNOSUPPORT            94       Socket type not supported
    EOPNOTSUPP                 95       Operation not supported on transport endpoint
    EPFNOSUPPORT               96       Protocol family not supported
    EAFNOSUPPORT               97       Address family not supported by protocol
    EADDRINUSE                 98       Address already in use
    EADDRNOTAVAIL              99       Cannot assign requested address
    ENETDOWN                   100      Network is down
    ENETUNREACH                101      Network is unreachable
    ENETRESET                  102      Network dropped connection because of reset
    ECONNABORTED               103      Software caused connection abort
    ECONNRESET                 104      Connection reset by peer
    ENOBUFS                    105      No buffer space available
    EISCONN                    106      Transport endpoint is already connected
    ENOTCONN                   107      Transport endpoint is not connected
    ESHUTDOWN                  108      Cannot send after transport endpoint shutdown
    ETOOMANYREFS               109      Too many references: cannot splice
    ETIMEDOUT                  110      Connection timed out
    ECONNREFUSED               111      Connection refused
    EHOSTDOWN                  112      Host is down
    EHOSTUNREACH               113      No route to host
    EALREADY                   114      Operation already in progress
    EINPROGRESS                115      Operation now in progress
    ESTALE                     116      Stale NFS file handle
    EUCLEAN                    117      Structure needs cleaning
    ENOTNAM                    118      Not a XENIX named type file
    ENAVAIL                    119      No XENIX semaphores available
    EISNAM                     120      Is a named type file
    EREMOTEIO                  121      Remote I/O error
    EDQUOT                     122      Quota exceeded
    ENOMEDIUM                  123      No medium found
    EMEDIUMTYPE                124      Wrong medium type
    ECANCELED                  125      Operation Canceled
    ENOKEY                     126      Required key not available
    EKEYEXPIRED                127      Key has expired
    EKEYREVOKED                128      Key has been revoked
    EKEYREJECTED               129      Key was rejected by service
    EOWNERDEAD                 130      Owner died
    ENOTRECOVERABLE            131      State not recoverable
    
Note:
MbedOS System Error codes are defined using the macro MBED_DEFINE_SYSTEM_ERROR
For example MBED_DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ) macro defines the following values:
ERROR_CODE_INVALID_ARGUMENT = MBED_SYSTEM_ERROR_BASE+1
ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)
Its effectively equivalent to:
ERROR_CODE_INVALID_ARGUMENT = 1
ERROR_INVALID_ARGUMENT = 0x80FF0001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN) New System Error codes should be defined using MBED_DEFINE_SYSTEM_ERROR macro and must have an unique error code value
passed as the second argument in the MBED_DEFINE_SYSTEM_ERROR macro.

Below are the Mbed System error codes and the description:
    UNKNOWN                    256      Unknown error
    INVALID_ARGUMENT           257      Invalid Argument
    INVALID_DATA               258      Invalid data
    INVALID_FORMAT             259      Invalid format
    INVALID_INDEX              260      Invalid Index
    INVALID_SIZE               261      Invalid Size
    INVALID_OPERATION          262      Invalid Operation
    NOT_FOUND                  263      Not Found
    ACCESS_DENIED              264      Access Denied
    NOT_SUPPORTED              265      Not supported
    BUFFER_FULL                266      Buffer Full
    MEDIA_FULL                 267      Media/Disk Full
    ALREADY_IN_USE             268      Already in use
    TIMEOUT                    269      Timeout error
    NOT_READY                  270      Not Ready
    FAILED_OPERATION           271      Requested Operation failed
    OPERATION_PROHIBITED       272      Operation prohibited
    OPERATION_ABORTED          273      Operation failed
    WRITE_PROTECTED            274      Attempt to write to write-protected resource
    NO_RESPONSE                275      No response
    SEMAPHORE_LOCK_FAILED      276      Semaphore lock failed
    MUTEX_LOCK_FAILED          277      Mutex lock failed
    SEMAPHORE_UNLOCK_FAILED    278      Semaphore unlock failed
    MUTEX_UNLOCK_FAILED        279      Mutex unlock failed
    CRC_ERROR                  280      CRC error or mismatch
    OPEN_FAILED                281      Open failed
    CLOSE_FAILED               282      Close failed
    READ_FAILED                283      Read failed
    WRITE_FAILED               284      Write failed
    INITIALIZATION_FAILED      285      Initialization failed
    BOOT_FAILURE               286      Boot failure
    OUT_OF_MEMORY              287      Out of memory
    OUT_OF_RESOURCES           288      Out of resources
    ALLOC_FAILED               289      Alloc failed
    FREE_FAILED                290      Free failed
    OVERFLOW                   291      Overflow error
    UNDERFLOW                  292      Underflow error
    STACK_OVERFLOW             293      Stack overflow error
    ISR_QUEUE_OVERFLOW         294      ISR queue overflow
    TIMER_QUEUE_OVERFLOW       295      Timer Queue overflow
    CLIB_SPACE_UNAVAILABLE     296      Standard library error - Space unavailable
    CLIB_EXCEPTION             297      Standard library error - Exception
    CLIB_MUTEX_INIT_FAILURE    298      Standard library error - Mutex Init failure
    CREATE_FAILED              299      Create failed
    DELETE_FAILED              300      Delete failed
    THREAD_CREATE_FAILED       301      Thread Create failed
    THREAD_DELETE_FAILED       302      Thread Delete failed
    PROHIBITED_IN_ISR_CONTEXT  303      Operation Prohibited in ISR context
    PINMAP_INVALID             304      Pinmap Invalid
    RTOS_EVENT                 305      Unknown Rtos Error
    RTOS_THREAD_EVENT          306      Rtos Thread Error
    RTOS_MUTEX_EVENT           307      Rtos Mutex Error
    RTOS_SEMAPHORE_EVENT       308      Rtos Semaphore Error
    RTOS_MEMORY_POOL_EVENT     309      Rtos Memory Pool Error
    RTOS_TIMER_EVENT           310      Rtos Timer Error
    RTOS_EVENT_FLAGS_EVENT     311      Rtos Event flags Error
    RTOS_MESSAGE_QUEUE_EVENT   312      Rtos Message queue Error
    DEVICE_BUSY                313      Device Busy
    CONFIG_UNSUPPORTED         314      Configuration not supported
    CONFIG_MISMATCH            315      Configuration mismatch
    ALREADY_INITIALIZED        316      Already initialized
    HARDFAULT_EXCEPTION        317      HardFault exception
    MEMMANAGE_EXCEPTION        318      MemManage exception
    BUSFAULT_EXCEPTION         319      BusFault exception
    USAGEFAULT_EXCEPTION       320      UsageFault exception
    BLE_NO_FRAME_INITIALIZED,  321      BLE No frame initialized
    BLE_BACKEND_CREATION_FAILED 322     BLE Backend creation failed
    BLE_BACKEND_NOT_INITIALIZED 323     BLE Backend not initialized
    ASSERTION_FAILED           324      Assertion Failed
    AUTHENTICATION_FAILED      325      Authentication Failed
    RBP_AUTHENTICATION_FAILED  326      Rollback Protect Authentication Failed
    
Custom Error codes can be defined using the macro DEFINE_CUSTOM_ERROR
This is mainly meant to capture non-generic error codes specific to a device. For example DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR ,1 ) macro defines the following values:
ERROR_CODE_MY_CUSTOM_ERROR = MBED_CUSTOM_ERROR_BASE+1
ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MBED_MODULE_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)
Its effectively equivalent to:
ERROR_CODE_MY_CUSTOM_ERROR = 4097
ERROR_MY_CUSTOM_ERROR = 0xA0FF1001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN)

**Using error codes:**
POSIX error codes may be used in modules/functions currently using POSIX error codes and switching them to Mbed-OS error codes may cause interoperability issues. For example, some of the filesystem, network stack implementations may need to use POSIX error codes in order to keep them compatible with other modules interfacing with them, and may continue to use POSIX error codes.

In all other cases, like for any native development of Mbed-OS modules Mbed-OS error codes should be used. This makes it easy to use Mbed-OS error reporting/logging infrastructure and makes debugging error scenarios much more efficient.

Note:
**Searching for error codes in mbed-os source tree:**
If you get an error report as below which you want to search for in mbed-os source tree, first take note of "Error Code" number.
For example, the below error report has an error code of 259. Find the error name associated with the error code and in this case its INVALID_FORMAT.
Use that error name(INVALID_FORMAT) to search the source tree for code locations setting that specific error code.
If the Error module reported is not 255(which indicates unknown module), you can also use that to narrow down to the specific component reporting the error. See mbed_module_type_t enum above for module mapping.
    ++ MbedOS Error Info ++
    Error Status: 0x80FF013D Code: 317 Module: 255
    Error Message: Fault exception
    Location: 0x5CD1
    Error Value: 0x4A2A
    Current Thread: Id: 0x20001E80 Entry: 0x5EB1 StackSize: 0x1000 StackMem: 0x20000E80 SP: 0x2002FF90
    For more info, visit: https://mbed.com/s/error?error=0x80FF013D&mbedos=999999&core=0x410FC241&compile=1&ver=5060528
    -- MbedOS Error Info --
    

mbed_error_code_t definition

mbed_error_code_t enumeration defines the Error codes and Error status values for MBED_MODULE_UNKNOWN.
It defines all of POSIX Error Codes/Statuses and Mbed System Error Codes/Statuses.

Note:
POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This effectively defines the following values:
ERROR_CODE_EPERM = EPERM
ERROR_EPERM = -EPERM

POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This macro defines the following values:
ERROR_CODE_EPERM = MBED_POSIX_ERROR_BASE+EPERM
ERROR_EPERM = -(MBED_POSIX_ERROR_BASE+EPERM)
Its effectively equivalent to:
ERROR_CODE_EPERM = 1
ERROR_EPERM = -1
All POSIX error codes currently supported by MbedOS(defined in mbed_retarget.h) are defined using the MBED_DEFINE_POSIX_ERROR macro.

Below are the POSIX error codes and the description:

    EPERM                      1        Operation not permitted
    ENOENT                     2        No such file or directory
    ESRCH                      3        No such process
    EINTR                      4        Interrupted system call
    EIO                        5        I/O error
    ENXIO                      6        No such device or address
    E2BIG                      7        Argument list too long
    ENOEXEC                    8        Exec format error
    EBADF                      9        Bad file number
    ECHILD                     10       No child processes
    EAGAIN                     11       Try again
    ENOMEM                     12       Out of memory
    EACCES                     13       Permission denied
    EFAULT                     14       Bad address
    ENOTBLK                    15       Block device required
    EBUSY                      16       Device or resource busy
    EEXIST                     17       File exists
    EXDEV                      18       Cross-device link
    ENODEV                     19       No such device
    ENOTDIR                    20       Not a directory
    EISDIR                     21       Is a directory
    EINVAL                     22       Invalid argument
    ENFILE                     23       File table overflow
    EMFILE                     24       Too many open files
    ENOTTY                     25       Not a typewriter
    ETXTBSY                    26       Text file busy
    EFBIG                      27       File too large
    ENOSPC                     28       No space left on device
    ESPIPE                     29       Illegal seek
    EROFS                      30       Read-only file system
    EMLINK                     31       Too many links
    EPIPE                      32       Broken pipe
    EDOM                       33       Math argument out of domain of func
    ERANGE                     34       Math result not representable
    EDEADLK                    35       Resource deadlock would occur
    ENAMETOOLONG               36       File name too long
    ENOLCK                     37       No record locks available
    ENOSYS                     38       Function not implemented
    ENOTEMPTY                  39       Directory not empty
    ELOOP                      40       Too many symbolic links encountered
    EWOULDBLOCK                EAGAIN   Operation would block
    ENOMSG                     42       No message of desired type
    EIDRM                      43       Identifier removed
    ECHRNG                     44       Channel number out of range
    EL2NSYNC                   45       Level 2 not synchronized
    EL3HLT                     46       Level 3 halted
    EL3RST                     47       Level 3 reset
    ELNRNG                     48       Link number out of range
    EUNATCH                    49       Protocol driver not attached
    ENOCSI                     50       No CSI structure available
    EL2HLT                     51       Level 2 halted
    EBADE                      52       Invalid exchange
    EBADR                      53       Invalid request descriptor
    EXFULL                     54       Exchange full
    ENOANO                     55       No anode
    EBADRQC                    56       Invalid request code
    EBADSLT                    57       Invalid slot
    EDEADLOCK                  EDEADLK  Resource deadlock would occur
    EBFONT                     59       Bad font file format
    ENOSTR                     60       Device not a stream
    ENODATA                    61       No data available
    ETIME                      62       Timer expired
    ENOSR                      63       Out of streams resources
    ENONET                     64       Machine is not on the network
    ENOPKG                     65       Package not installed
    EREMOTE                    66       Object is remote
    ENOLINK                    67       Link has been severed
    EADV                       68       Advertise error
    ESRMNT                     69       Srmount error
    ECOMM                      70       Communication error on send
    EPROTO                     71       Protocol error
    EMULTIHOP                  72       Multihop attempted
    EDOTDOT                    73       RFS specific error
    EBADMSG                    74       Not a data message
    EOVERFLOW                  75       Value too large for defined data type
    ENOTUNIQ                   76       Name not unique on network
    EBADFD                     77       File descriptor in bad state
    EREMCHG                    78       Remote address changed
    ELIBACC                    79       Can not access a needed shared library
    ELIBBAD                    80       Accessing a corrupted shared library
    ELIBSCN                    81       .lib section in a.out corrupted
    ELIBMAX                    82       Attempting to link in too many shared libraries
    ELIBEXEC                   83       Cannot exec a shared library directly
    EILSEQ                     84       Illegal byte sequence
    ERESTART                   85       Interrupted system call should be restarted
    ESTRPIPE                   86       Streams pipe error
    EUSERS                     87       Too many users
    ENOTSOCK                   88       Socket operation on non-socket
    EDESTADDRREQ               89       Destination address required
    EMSGSIZE                   90       Message too long
    EPROTOTYPE                 91       Protocol wrong type for socket
    ENOPROTOOPT                92       Protocol not available
    EPROTONOSUPPORT            93       Protocol not supported
    ESOCKTNOSUPPORT            94       Socket type not supported
    EOPNOTSUPP                 95       Operation not supported on transport endpoint
    EPFNOSUPPORT               96       Protocol family not supported
    EAFNOSUPPORT               97       Address family not supported by protocol
    EADDRINUSE                 98       Address already in use
    EADDRNOTAVAIL              99       Cannot assign requested address
    ENETDOWN                   100      Network is down
    ENETUNREACH                101      Network is unreachable
    ENETRESET                  102      Network dropped connection because of reset
    ECONNABORTED               103      Software caused connection abort
    ECONNRESET                 104      Connection reset by peer
    ENOBUFS                    105      No buffer space available
    EISCONN                    106      Transport endpoint is already connected
    ENOTCONN                   107      Transport endpoint is not connected
    ESHUTDOWN                  108      Cannot send after transport endpoint shutdown
    ETOOMANYREFS               109      Too many references: cannot splice
    ETIMEDOUT                  110      Connection timed out
    ECONNREFUSED               111      Connection refused
    EHOSTDOWN                  112      Host is down
    EHOSTUNREACH               113      No route to host
    EALREADY                   114      Operation already in progress
    EINPROGRESS                115      Operation now in progress
    ESTALE                     116      Stale NFS file handle
    EUCLEAN                    117      Structure needs cleaning
    ENOTNAM                    118      Not a XENIX named type file
    ENAVAIL                    119      No XENIX semaphores available
    EISNAM                     120      Is a named type file
    EREMOTEIO                  121      Remote I/O error
    EDQUOT                     122      Quota exceeded
    ENOMEDIUM                  123      No medium found
    EMEDIUMTYPE                124      Wrong medium type
    ECANCELED                  125      Operation Canceled
    ENOKEY                     126      Required key not available
    EKEYEXPIRED                127      Key has expired
    EKEYREVOKED                128      Key has been revoked
    EKEYREJECTED               129      Key was rejected by service
    EOWNERDEAD                 130      Owner died
    ENOTRECOVERABLE            131      State not recoverable
    
Note:
MbedOS System Error codes are defined using the macro MBED_DEFINE_SYSTEM_ERROR
For example MBED_DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ) macro defines the following values:
ERROR_CODE_INVALID_ARGUMENT = MBED_SYSTEM_ERROR_BASE+1
ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)
Its effectively equivalent to:
ERROR_CODE_INVALID_ARGUMENT = 1
ERROR_INVALID_ARGUMENT = 0x80FF0001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN) New System Error codes should be defined using MBED_DEFINE_SYSTEM_ERROR macro and must have an unique error code value
passed as the second argument in the MBED_DEFINE_SYSTEM_ERROR macro.

Below are the Mbed System error codes and the description:
    UNKNOWN                    256      Unknown error
    INVALID_ARGUMENT           257      Invalid Argument
    INVALID_DATA               258      Invalid data
    INVALID_FORMAT             259      Invalid format
    INVALID_INDEX              260      Invalid Index
    INVALID_SIZE               261      Invalid Size
    INVALID_OPERATION          262      Invalid Operation
    NOT_FOUND                  263      Not Found
    ACCESS_DENIED              264      Access Denied
    NOT_SUPPORTED              265      Not supported
    BUFFER_FULL                266      Buffer Full
    MEDIA_FULL                 267      Media/Disk Full
    ALREADY_IN_USE             268      Already in use
    TIMEOUT                    269      Timeout error
    NOT_READY                  270      Not Ready
    FAILED_OPERATION           271      Requested Operation failed
    OPERATION_PROHIBITED       272      Operation prohibited
    OPERATION_ABORTED          273      Operation failed
    WRITE_PROTECTED            274      Attempt to write to write-protected resource
    NO_RESPONSE                275      No response
    SEMAPHORE_LOCK_FAILED      276      Semaphore lock failed
    MUTEX_LOCK_FAILED          277      Mutex lock failed
    SEMAPHORE_UNLOCK_FAILED    278      Semaphore unlock failed
    MUTEX_UNLOCK_FAILED        279      Mutex unlock failed
    CRC_ERROR                  280      CRC error or mismatch
    OPEN_FAILED                281      Open failed
    CLOSE_FAILED               282      Close failed
    READ_FAILED                283      Read failed
    WRITE_FAILED               284      Write failed
    INITIALIZATION_FAILED      285      Initialization failed
    BOOT_FAILURE               286      Boot failure
    OUT_OF_MEMORY              287      Out of memory
    OUT_OF_RESOURCES           288      Out of resources
    ALLOC_FAILED               289      Alloc failed
    FREE_FAILED                290      Free failed
    OVERFLOW                   291      Overflow error
    UNDERFLOW                  292      Underflow error
    STACK_OVERFLOW             293      Stack overflow error
    ISR_QUEUE_OVERFLOW         294      ISR queue overflow
    TIMER_QUEUE_OVERFLOW       295      Timer Queue overflow
    CLIB_SPACE_UNAVAILABLE     296      Standard library error - Space unavailable
    CLIB_EXCEPTION             297      Standard library error - Exception
    CLIB_MUTEX_INIT_FAILURE    298      Standard library error - Mutex Init failure
    CREATE_FAILED              299      Create failed
    DELETE_FAILED              300      Delete failed
    THREAD_CREATE_FAILED       301      Thread Create failed
    THREAD_DELETE_FAILED       302      Thread Delete failed
    PROHIBITED_IN_ISR_CONTEXT  303      Operation Prohibited in ISR context
    PINMAP_INVALID             304      Pinmap Invalid
    RTOS_EVENT                 305      Unknown Rtos Error
    RTOS_THREAD_EVENT          306      Rtos Thread Error
    RTOS_MUTEX_EVENT           307      Rtos Mutex Error
    RTOS_SEMAPHORE_EVENT       308      Rtos Semaphore Error
    RTOS_MEMORY_POOL_EVENT     309      Rtos Memory Pool Error
    RTOS_TIMER_EVENT           310      Rtos Timer Error
    RTOS_EVENT_FLAGS_EVENT     311      Rtos Event flags Error
    RTOS_MESSAGE_QUEUE_EVENT   312      Rtos Message queue Error
    DEVICE_BUSY                313      Device Busy
    CONFIG_UNSUPPORTED         314      Configuration not supported
    CONFIG_MISMATCH            315      Configuration mismatch
    ALREADY_INITIALIZED        316      Already initialized
    HARDFAULT_EXCEPTION        317      HardFault exception
    MEMMANAGE_EXCEPTION        318      MemManage exception
    BUSFAULT_EXCEPTION         319      BusFault exception
    USAGEFAULT_EXCEPTION       320      UsageFault exception
    BLE_NO_FRAME_INITIALIZED,  321      BLE No frame initialized
    BLE_BACKEND_CREATION_FAILED 322     BLE Backend creation failed
    BLE_BACKEND_NOT_INITIALIZED 323     BLE Backend not initialized
    ASSERTION_FAILED           324      Assertion Failed
    AUTHENTICATION_FAILED      325      Authentication Failed
    RBP_AUTHENTICATION_FAILED  326      Rollback Protect Authentication Failed
    
Custom Error codes can be defined using the macro DEFINE_CUSTOM_ERROR
This is mainly meant to capture non-generic error codes specific to a device. For example DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR ,1 ) macro defines the following values:
ERROR_CODE_MY_CUSTOM_ERROR = MBED_CUSTOM_ERROR_BASE+1
ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MBED_MODULE_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)
Its effectively equivalent to:
ERROR_CODE_MY_CUSTOM_ERROR = 4097
ERROR_MY_CUSTOM_ERROR = 0xA0FF1001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN)

**Using error codes:**
POSIX error codes may be used in modules/functions currently using POSIX error codes and switching them to Mbed-OS error codes may cause interoperability issues. For example, some of the filesystem, network stack implementations may need to use POSIX error codes in order to keep them compatible with other modules interfacing with them, and may continue to use POSIX error codes.

In all other cases, like for any native development of Mbed-OS modules Mbed-OS error codes should be used. This makes it easy to use Mbed-OS error reporting/logging infrastructure and makes debugging error scenarios much more efficient.

Note:
**Searching for error codes in mbed-os source tree:**
If you get an error report as below which you want to search for in mbed-os source tree, first take note of "Error Code" number.
For example, the below error report has an error code of 259. Find the error name associated with the error code and in this case its INVALID_FORMAT.
Use that error name(INVALID_FORMAT) to search the source tree for code locations setting that specific error code.
If the Error module reported is not 255(which indicates unknown module), you can also use that to narrow down to the specific component reporting the error. See mbed_module_type_t enum above for module mapping.
    ++ MbedOS Error Info ++
    Error Status: 0x80FF013D Code: 317 Module: 255
    Error Message: Fault exception
    Location: 0x5CD1
    Error Value: 0x4A2A
    Current Thread: Id: 0x20001E80 Entry: 0x5EB1 StackSize: 0x1000 StackMem: 0x20000E80 SP: 0x2002FF90
    For more info, visit: https://mbed.com/s/error?error=0x80FF013D&mbedos=999999&core=0x410FC241&compile=1&ver=5060528
    -- MbedOS Error Info --
    

mbed_error_ctx struct

This struct captures the context information at the time of error.
It primarily contains information about the thread where the error originated,
filename/line number of the source file where the error occurred, a context specific error value(error_value)
and the address where the error originated.

Note:
Below are the members of mbed_error_ctx struct
error_status mbed_error_status_t value for this error
error_function_address Address where the error occurred
thread_id ID of the thread which generated the error
thread_entry_address Entry function of the thread which generated the error
thread_stack_size Stack Size of the thread which generated the error
thread_stack_mem Stack Top of the thread which generated the error
thread_current_sp Current Stack Pointer of the thread which generated the error
error_value A context/error specific value associated with this error
error_filename Filename where the error originated
error_line_number Line number in error_filename where the error originated

mbed_error_ctx struct

This struct captures the context information at the time of error.
It primarily contains information about the thread where the error originated,
filename/line number of the source file where the error occurred, a context specific error value(error_value)
and the address where the error originated.

Note:
Below are the members of mbed_error_ctx struct
error_status mbed_error_status_t value for this error
error_function_address Address where the error occurred
thread_id ID of the thread which generated the error
thread_entry_address Entry function of the thread which generated the error
thread_stack_size Stack Size of the thread which generated the error
thread_stack_mem Stack Top of the thread which generated the error
thread_current_sp Current Stack Pointer of the thread which generated the error
error_value A context/error specific value associated with this error
error_filename Filename where the error originated
error_line_number Line number in error_filename where the error originated
typedef void(* mbed_error_hook_t)(const mbed_error_ctx *error_ctx)

Callback/Error hook function prototype.

Applications needing a callback when an error is reported can use mbed_set_error_hook function to register a callback/error hook function using the following prototype. When an error happens in the system error handling implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.

Parameters:
error_ctxError context structure associated with this error.
Returns:
void

Definition at line 944 of file cmsis/BUILD/mbed/platform/mbed_error.h.

typedef void(* mbed_error_hook_t)(const mbed_error_ctx *error_ctx)

Callback/Error hook function prototype.

Applications needing a callback when an error is reported can use mbed_set_error_hook function to register a callback/error hook function using the following prototype. When an error happens in the system error handling implementation will invoke this callback with the mbed_error_status_t reported and the error context at the time of error.

Parameters:
error_ctxError context structure associated with this error.
Returns:
void

Definition at line 944 of file platform/mbed_error.h.

typedef int mbed_error_status_t

mbed_error_status_t description

mbed_error_status_t type represents the error status values under MbedOS. mbed_error_status_t values are signed integers and always be negative.
Internally its encoded as below with bit-fields representing error type, module and error code:

mbed_error_status_t Status Encoding:

 | 31 Always Negative | 30-29(2 bits)  | 28-24              | 23-16(8 bits) | 15-0(16 bits) |
 | -1                 | TYPE           | (unused/reserved)  | MODULE TYPE    | ERROR CODE    |
 

The error status value range for each error type is as follows:
POSIX Error Status-es - 0xFFFFFFFF to 0xFFFFFF01(-1 -255) - This corresponds to POSIX error codes represented as negative.
System Error Status-es - 0x80XX0100 to 0x80XX0FFF - This corresponds to System error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)
Custom Error Status-es - 0xA0XX1000 to 0xA0XXFFFF - This corresponds to Custom error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)

The ERROR CODE(values encoded into ERROR CODE bit-field in mbed_error_status_t) value range for each error type is also separated as below:
POSIX Error Codes - 1 to 255.
System Error Codes - 256 to 4095.
Custom Error Codes - 4096 to 65535.

Note:
POSIX error codes are always encoded as negative of their actual value. For example, EPERM is encoded as -EPERM. And, the MODULE TYPE for POSIX error codes are always encoded as MBED_MODULE_UNKNOWN.
This is to enable easy injection of POSIX error codes into MbedOS error handling system without altering the actual POSIX error values.
Accordingly, POSIX error codes are represented as -1 to -255 under MbedOS error status representation.

Definition at line 104 of file cmsis/BUILD/mbed/platform/mbed_error.h.

typedef int mbed_error_status_t

mbed_error_status_t description

mbed_error_status_t type represents the error status values under MbedOS. mbed_error_status_t values are signed integers and always be negative.
Internally its encoded as below with bit-fields representing error type, module and error code:

mbed_error_status_t Status Encoding:

 | 31 Always Negative | 30-29(2 bits)  | 28-24              | 23-16(8 bits) | 15-0(16 bits) |
 | -1                 | TYPE           | (unused/reserved)  | MODULE TYPE    | ERROR CODE    |
 

The error status value range for each error type is as follows:
POSIX Error Status-es - 0xFFFFFFFF to 0xFFFFFF01(-1 -255) - This corresponds to POSIX error codes represented as negative.
System Error Status-es - 0x80XX0100 to 0x80XX0FFF - This corresponds to System error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)
Custom Error Status-es - 0xA0XX1000 to 0xA0XXFFFF - This corresponds to Custom error codes range(all values are negative). Bits 23-16 will be module type(marked with XX)

The ERROR CODE(values encoded into ERROR CODE bit-field in mbed_error_status_t) value range for each error type is also separated as below:
POSIX Error Codes - 1 to 255.
System Error Codes - 256 to 4095.
Custom Error Codes - 4096 to 65535.

Note:
POSIX error codes are always encoded as negative of their actual value. For example, EPERM is encoded as -EPERM. And, the MODULE TYPE for POSIX error codes are always encoded as MBED_MODULE_UNKNOWN.
This is to enable easy injection of POSIX error codes into MbedOS error handling system without altering the actual POSIX error values.
Accordingly, POSIX error codes are represented as -1 to -255 under MbedOS error status representation.

Definition at line 104 of file platform/mbed_error.h.

mbed_error_type_t definition

Note:
This enumeration defines the Error types supported. The value of these enum values will be encoded into mbed_error_status_t TYPE field.
See mbed_error_status_t description for more info.
MBED_ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.
MBED_ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.
MBED_ERROR_TYPE_POSIX - Used to indicate that the error status is of POSIX error type.

mbed_error_type_t definition

Note:
This enumeration defines the Error types supported. The value of these enum values will be encoded into mbed_error_status_t TYPE field.
See mbed_error_status_t description for more info.
MBED_ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.
MBED_ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.
MBED_ERROR_TYPE_POSIX - Used to indicate that the error status is of POSIX error type.

mbed_module_type_t definition

Note:
This enumeration defines the module types. The value of these enum values will be encoded into mbed_error_status_t MODULE field.

See mbed_error_status_t description for more info.
MBED_MODULE_UNKNOWN - This module type can be used if caller of the mbed_error/mbed_warning doesn't know who is the actual originator of the error.
Other module values can be used to provide more info on who/where the error originated from.

For example, if I2C driver is the component originating the error you can use MBED_MODULE_DRIVER_I2C to provide more info.
Its used in call to MBED_MAKE_ERROR/MBED_MAKE_SYSTEM_ERROR/MBED_MAKE_CUSTOM_ERROR macros.
      Example: mbed_error_status_t i2c_driver_error = MBED_MAKE_ERROR( MBED_MODULE_DRIVER_I2C, MBED_ERROR_CONFIG_UNSUPPORTED );
Note:

Below are the module code mappings:
    MBED_MODULE_APPLICATION                     0       Application
    MBED_MODULE_PLATFORM                        1       Platform
    MBED_MODULE_KERNEL                          2       RTX Kernel
    MBED_MODULE_NETWORK_STACK                   3       Network stack
    MBED_MODULE_HAL                             4       HAL - Hardware Abstraction Layer
    MBED_MODULE_MEMORY_SUBSYSTEM                5       Memory Subsystem
    MBED_MODULE_FILESYSTEM                      6       Filesystem
    MBED_MODULE_BLOCK_DEVICE                    7       Block device
    MBED_MODULE_DRIVER                          8       Driver
    MBED_MODULE_DRIVER_SERIAL                   9       Serial Driver
    MBED_MODULE_DRIVER_RTC                      10      RTC Driver
    MBED_MODULE_DRIVER_I2C                      11      I2C Driver
    MBED_MODULE_DRIVER_SPI                      12      SPI Driver
    MBED_MODULE_DRIVER_GPIO                     13      GPIO Driver
    MBED_MODULE_DRIVER_ANALOG                   14      Analog Driver
    MBED_MODULE_DRIVER_DIGITAL                  15      DigitalIO Driver
    MBED_MODULE_DRIVER_CAN                      16      CAN Driver
    MBED_MODULE_DRIVER_ETHERNET                 17      Ethernet Driver
    MBED_MODULE_DRIVER_CRC                      18      CRC Module
    MBED_MODULE_DRIVER_PWM                      19      PWM Driver
    MBED_MODULE_DRIVER_QSPI                     20      QSPI Driver
    MBED_MODULE_DRIVER_USB                      21      USB Driver
    MBED_MODULE_TARGET_SDK                      22      SDK
    MBED_MODULE_BLE                             23      BLE
    MBED_MODULE_NETWORK_STATS                   24      Network Statistics

    MBED_MODULE_UNKNOWN                         255     Unknown module
    

mbed_module_type_t definition

Note:
This enumeration defines the module types. The value of these enum values will be encoded into mbed_error_status_t MODULE field.

See mbed_error_status_t description for more info.
MBED_MODULE_UNKNOWN - This module type can be used if caller of the mbed_error/mbed_warning doesn't know who is the actual originator of the error.
Other module values can be used to provide more info on who/where the error originated from.

For example, if I2C driver is the component originating the error you can use MBED_MODULE_DRIVER_I2C to provide more info.
Its used in call to MBED_MAKE_ERROR/MBED_MAKE_SYSTEM_ERROR/MBED_MAKE_CUSTOM_ERROR macros.
      Example: mbed_error_status_t i2c_driver_error = MBED_MAKE_ERROR( MBED_MODULE_DRIVER_I2C, MBED_ERROR_CONFIG_UNSUPPORTED );
Note:

Below are the module code mappings:
    MBED_MODULE_APPLICATION                     0       Application
    MBED_MODULE_PLATFORM                        1       Platform
    MBED_MODULE_KERNEL                          2       RTX Kernel
    MBED_MODULE_NETWORK_STACK                   3       Network stack
    MBED_MODULE_HAL                             4       HAL - Hardware Abstraction Layer
    MBED_MODULE_MEMORY_SUBSYSTEM                5       Memory Subsystem
    MBED_MODULE_FILESYSTEM                      6       Filesystem
    MBED_MODULE_BLOCK_DEVICE                    7       Block device
    MBED_MODULE_DRIVER                          8       Driver
    MBED_MODULE_DRIVER_SERIAL                   9       Serial Driver
    MBED_MODULE_DRIVER_RTC                      10      RTC Driver
    MBED_MODULE_DRIVER_I2C                      11      I2C Driver
    MBED_MODULE_DRIVER_SPI                      12      SPI Driver
    MBED_MODULE_DRIVER_GPIO                     13      GPIO Driver
    MBED_MODULE_DRIVER_ANALOG                   14      Analog Driver
    MBED_MODULE_DRIVER_DIGITAL                  15      DigitalIO Driver
    MBED_MODULE_DRIVER_CAN                      16      CAN Driver
    MBED_MODULE_DRIVER_ETHERNET                 17      Ethernet Driver
    MBED_MODULE_DRIVER_CRC                      18      CRC Module
    MBED_MODULE_DRIVER_PWM                      19      PWM Driver
    MBED_MODULE_DRIVER_QSPI                     20      QSPI Driver
    MBED_MODULE_DRIVER_USB                      21      USB Driver
    MBED_MODULE_TARGET_SDK                      22      SDK
    MBED_MODULE_BLE                             23      BLE
    MBED_MODULE_NETWORK_STATS                   24      Network Statistics

    MBED_MODULE_UNKNOWN                         255     Unknown module
    

Enumeration Type Documentation

mbed_error_code_t definition

mbed_error_code_t enumeration defines the Error codes and Error status values for MBED_MODULE_UNKNOWN.
It defines all of POSIX Error Codes/Statuses and Mbed System Error Codes/Statuses.

Note:
POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This effectively defines the following values:
ERROR_CODE_EPERM = EPERM
ERROR_EPERM = -EPERM

POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This macro defines the following values:
ERROR_CODE_EPERM = MBED_POSIX_ERROR_BASE+EPERM
ERROR_EPERM = -(MBED_POSIX_ERROR_BASE+EPERM)
Its effectively equivalent to:
ERROR_CODE_EPERM = 1
ERROR_EPERM = -1
All POSIX error codes currently supported by MbedOS(defined in mbed_retarget.h) are defined using the MBED_DEFINE_POSIX_ERROR macro.

Below are the POSIX error codes and the description:

    EPERM                      1        Operation not permitted
    ENOENT                     2        No such file or directory
    ESRCH                      3        No such process
    EINTR                      4        Interrupted system call
    EIO                        5        I/O error
    ENXIO                      6        No such device or address
    E2BIG                      7        Argument list too long
    ENOEXEC                    8        Exec format error
    EBADF                      9        Bad file number
    ECHILD                     10       No child processes
    EAGAIN                     11       Try again
    ENOMEM                     12       Out of memory
    EACCES                     13       Permission denied
    EFAULT                     14       Bad address
    ENOTBLK                    15       Block device required
    EBUSY                      16       Device or resource busy
    EEXIST                     17       File exists
    EXDEV                      18       Cross-device link
    ENODEV                     19       No such device
    ENOTDIR                    20       Not a directory
    EISDIR                     21       Is a directory
    EINVAL                     22       Invalid argument
    ENFILE                     23       File table overflow
    EMFILE                     24       Too many open files
    ENOTTY                     25       Not a typewriter
    ETXTBSY                    26       Text file busy
    EFBIG                      27       File too large
    ENOSPC                     28       No space left on device
    ESPIPE                     29       Illegal seek
    EROFS                      30       Read-only file system
    EMLINK                     31       Too many links
    EPIPE                      32       Broken pipe
    EDOM                       33       Math argument out of domain of func
    ERANGE                     34       Math result not representable
    EDEADLK                    35       Resource deadlock would occur
    ENAMETOOLONG               36       File name too long
    ENOLCK                     37       No record locks available
    ENOSYS                     38       Function not implemented
    ENOTEMPTY                  39       Directory not empty
    ELOOP                      40       Too many symbolic links encountered
    EWOULDBLOCK                EAGAIN   Operation would block
    ENOMSG                     42       No message of desired type
    EIDRM                      43       Identifier removed
    ECHRNG                     44       Channel number out of range
    EL2NSYNC                   45       Level 2 not synchronized
    EL3HLT                     46       Level 3 halted
    EL3RST                     47       Level 3 reset
    ELNRNG                     48       Link number out of range
    EUNATCH                    49       Protocol driver not attached
    ENOCSI                     50       No CSI structure available
    EL2HLT                     51       Level 2 halted
    EBADE                      52       Invalid exchange
    EBADR                      53       Invalid request descriptor
    EXFULL                     54       Exchange full
    ENOANO                     55       No anode
    EBADRQC                    56       Invalid request code
    EBADSLT                    57       Invalid slot
    EDEADLOCK                  EDEADLK  Resource deadlock would occur
    EBFONT                     59       Bad font file format
    ENOSTR                     60       Device not a stream
    ENODATA                    61       No data available
    ETIME                      62       Timer expired
    ENOSR                      63       Out of streams resources
    ENONET                     64       Machine is not on the network
    ENOPKG                     65       Package not installed
    EREMOTE                    66       Object is remote
    ENOLINK                    67       Link has been severed
    EADV                       68       Advertise error
    ESRMNT                     69       Srmount error
    ECOMM                      70       Communication error on send
    EPROTO                     71       Protocol error
    EMULTIHOP                  72       Multihop attempted
    EDOTDOT                    73       RFS specific error
    EBADMSG                    74       Not a data message
    EOVERFLOW                  75       Value too large for defined data type
    ENOTUNIQ                   76       Name not unique on network
    EBADFD                     77       File descriptor in bad state
    EREMCHG                    78       Remote address changed
    ELIBACC                    79       Can not access a needed shared library
    ELIBBAD                    80       Accessing a corrupted shared library
    ELIBSCN                    81       .lib section in a.out corrupted
    ELIBMAX                    82       Attempting to link in too many shared libraries
    ELIBEXEC                   83       Cannot exec a shared library directly
    EILSEQ                     84       Illegal byte sequence
    ERESTART                   85       Interrupted system call should be restarted
    ESTRPIPE                   86       Streams pipe error
    EUSERS                     87       Too many users
    ENOTSOCK                   88       Socket operation on non-socket
    EDESTADDRREQ               89       Destination address required
    EMSGSIZE                   90       Message too long
    EPROTOTYPE                 91       Protocol wrong type for socket
    ENOPROTOOPT                92       Protocol not available
    EPROTONOSUPPORT            93       Protocol not supported
    ESOCKTNOSUPPORT            94       Socket type not supported
    EOPNOTSUPP                 95       Operation not supported on transport endpoint
    EPFNOSUPPORT               96       Protocol family not supported
    EAFNOSUPPORT               97       Address family not supported by protocol
    EADDRINUSE                 98       Address already in use
    EADDRNOTAVAIL              99       Cannot assign requested address
    ENETDOWN                   100      Network is down
    ENETUNREACH                101      Network is unreachable
    ENETRESET                  102      Network dropped connection because of reset
    ECONNABORTED               103      Software caused connection abort
    ECONNRESET                 104      Connection reset by peer
    ENOBUFS                    105      No buffer space available
    EISCONN                    106      Transport endpoint is already connected
    ENOTCONN                   107      Transport endpoint is not connected
    ESHUTDOWN                  108      Cannot send after transport endpoint shutdown
    ETOOMANYREFS               109      Too many references: cannot splice
    ETIMEDOUT                  110      Connection timed out
    ECONNREFUSED               111      Connection refused
    EHOSTDOWN                  112      Host is down
    EHOSTUNREACH               113      No route to host
    EALREADY                   114      Operation already in progress
    EINPROGRESS                115      Operation now in progress
    ESTALE                     116      Stale NFS file handle
    EUCLEAN                    117      Structure needs cleaning
    ENOTNAM                    118      Not a XENIX named type file
    ENAVAIL                    119      No XENIX semaphores available
    EISNAM                     120      Is a named type file
    EREMOTEIO                  121      Remote I/O error
    EDQUOT                     122      Quota exceeded
    ENOMEDIUM                  123      No medium found
    EMEDIUMTYPE                124      Wrong medium type
    ECANCELED                  125      Operation Canceled
    ENOKEY                     126      Required key not available
    EKEYEXPIRED                127      Key has expired
    EKEYREVOKED                128      Key has been revoked
    EKEYREJECTED               129      Key was rejected by service
    EOWNERDEAD                 130      Owner died
    ENOTRECOVERABLE            131      State not recoverable
    
Note:
MbedOS System Error codes are defined using the macro MBED_DEFINE_SYSTEM_ERROR
For example MBED_DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ) macro defines the following values:
ERROR_CODE_INVALID_ARGUMENT = MBED_SYSTEM_ERROR_BASE+1
ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)
Its effectively equivalent to:
ERROR_CODE_INVALID_ARGUMENT = 1
ERROR_INVALID_ARGUMENT = 0x80FF0001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN) New System Error codes should be defined using MBED_DEFINE_SYSTEM_ERROR macro and must have an unique error code value
passed as the second argument in the MBED_DEFINE_SYSTEM_ERROR macro.

Below are the Mbed System error codes and the description:
    UNKNOWN                    256      Unknown error
    INVALID_ARGUMENT           257      Invalid Argument
    INVALID_DATA               258      Invalid data
    INVALID_FORMAT             259      Invalid format
    INVALID_INDEX              260      Invalid Index
    INVALID_SIZE               261      Invalid Size
    INVALID_OPERATION          262      Invalid Operation
    NOT_FOUND                  263      Not Found
    ACCESS_DENIED              264      Access Denied
    NOT_SUPPORTED              265      Not supported
    BUFFER_FULL                266      Buffer Full
    MEDIA_FULL                 267      Media/Disk Full
    ALREADY_IN_USE             268      Already in use
    TIMEOUT                    269      Timeout error
    NOT_READY                  270      Not Ready
    FAILED_OPERATION           271      Requested Operation failed
    OPERATION_PROHIBITED       272      Operation prohibited
    OPERATION_ABORTED          273      Operation failed
    WRITE_PROTECTED            274      Attempt to write to write-protected resource
    NO_RESPONSE                275      No response
    SEMAPHORE_LOCK_FAILED      276      Semaphore lock failed
    MUTEX_LOCK_FAILED          277      Mutex lock failed
    SEMAPHORE_UNLOCK_FAILED    278      Semaphore unlock failed
    MUTEX_UNLOCK_FAILED        279      Mutex unlock failed
    CRC_ERROR                  280      CRC error or mismatch
    OPEN_FAILED                281      Open failed
    CLOSE_FAILED               282      Close failed
    READ_FAILED                283      Read failed
    WRITE_FAILED               284      Write failed
    INITIALIZATION_FAILED      285      Initialization failed
    BOOT_FAILURE               286      Boot failure
    OUT_OF_MEMORY              287      Out of memory
    OUT_OF_RESOURCES           288      Out of resources
    ALLOC_FAILED               289      Alloc failed
    FREE_FAILED                290      Free failed
    OVERFLOW                   291      Overflow error
    UNDERFLOW                  292      Underflow error
    STACK_OVERFLOW             293      Stack overflow error
    ISR_QUEUE_OVERFLOW         294      ISR queue overflow
    TIMER_QUEUE_OVERFLOW       295      Timer Queue overflow
    CLIB_SPACE_UNAVAILABLE     296      Standard library error - Space unavailable
    CLIB_EXCEPTION             297      Standard library error - Exception
    CLIB_MUTEX_INIT_FAILURE    298      Standard library error - Mutex Init failure
    CREATE_FAILED              299      Create failed
    DELETE_FAILED              300      Delete failed
    THREAD_CREATE_FAILED       301      Thread Create failed
    THREAD_DELETE_FAILED       302      Thread Delete failed
    PROHIBITED_IN_ISR_CONTEXT  303      Operation Prohibited in ISR context
    PINMAP_INVALID             304      Pinmap Invalid
    RTOS_EVENT                 305      Unknown Rtos Error
    RTOS_THREAD_EVENT          306      Rtos Thread Error
    RTOS_MUTEX_EVENT           307      Rtos Mutex Error
    RTOS_SEMAPHORE_EVENT       308      Rtos Semaphore Error
    RTOS_MEMORY_POOL_EVENT     309      Rtos Memory Pool Error
    RTOS_TIMER_EVENT           310      Rtos Timer Error
    RTOS_EVENT_FLAGS_EVENT     311      Rtos Event flags Error
    RTOS_MESSAGE_QUEUE_EVENT   312      Rtos Message queue Error
    DEVICE_BUSY                313      Device Busy
    CONFIG_UNSUPPORTED         314      Configuration not supported
    CONFIG_MISMATCH            315      Configuration mismatch
    ALREADY_INITIALIZED        316      Already initialized
    HARDFAULT_EXCEPTION        317      HardFault exception
    MEMMANAGE_EXCEPTION        318      MemManage exception
    BUSFAULT_EXCEPTION         319      BusFault exception
    USAGEFAULT_EXCEPTION       320      UsageFault exception
    BLE_NO_FRAME_INITIALIZED,  321      BLE No frame initialized
    BLE_BACKEND_CREATION_FAILED 322     BLE Backend creation failed
    BLE_BACKEND_NOT_INITIALIZED 323     BLE Backend not initialized
    ASSERTION_FAILED           324      Assertion Failed
    AUTHENTICATION_FAILED      325      Authentication Failed
    RBP_AUTHENTICATION_FAILED  326      Rollback Protect Authentication Failed
    
Custom Error codes can be defined using the macro DEFINE_CUSTOM_ERROR
This is mainly meant to capture non-generic error codes specific to a device. For example DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR ,1 ) macro defines the following values:
ERROR_CODE_MY_CUSTOM_ERROR = MBED_CUSTOM_ERROR_BASE+1
ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MBED_MODULE_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)
Its effectively equivalent to:
ERROR_CODE_MY_CUSTOM_ERROR = 4097
ERROR_MY_CUSTOM_ERROR = 0xA0FF1001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN)

**Using error codes:**
POSIX error codes may be used in modules/functions currently using POSIX error codes and switching them to Mbed-OS error codes may cause interoperability issues. For example, some of the filesystem, network stack implementations may need to use POSIX error codes in order to keep them compatible with other modules interfacing with them, and may continue to use POSIX error codes.

In all other cases, like for any native development of Mbed-OS modules Mbed-OS error codes should be used. This makes it easy to use Mbed-OS error reporting/logging infrastructure and makes debugging error scenarios much more efficient.

Note:
**Searching for error codes in mbed-os source tree:**
If you get an error report as below which you want to search for in mbed-os source tree, first take note of "Error Code" number.
For example, the below error report has an error code of 259. Find the error name associated with the error code and in this case its INVALID_FORMAT.
Use that error name(INVALID_FORMAT) to search the source tree for code locations setting that specific error code.
If the Error module reported is not 255(which indicates unknown module), you can also use that to narrow down to the specific component reporting the error. See mbed_module_type_t enum above for module mapping.
    ++ MbedOS Error Info ++
    Error Status: 0x80FF013D Code: 317 Module: 255
    Error Message: Fault exception
    Location: 0x5CD1
    Error Value: 0x4A2A
    Current Thread: Id: 0x20001E80 Entry: 0x5EB1 StackSize: 0x1000 StackMem: 0x20000E80 SP: 0x2002FF90
    For more info, visit: https://mbed.com/s/error?error=0x80FF013D&mbedos=999999&core=0x410FC241&compile=1&ver=5060528
    -- MbedOS Error Info --
    

Definition at line 583 of file cmsis/BUILD/mbed/platform/mbed_error.h.

mbed_error_code_t definition

mbed_error_code_t enumeration defines the Error codes and Error status values for MBED_MODULE_UNKNOWN.
It defines all of POSIX Error Codes/Statuses and Mbed System Error Codes/Statuses.

Note:
POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This effectively defines the following values:
ERROR_CODE_EPERM = EPERM
ERROR_EPERM = -EPERM

POSIX Error codes are defined using the macro MBED_DEFINE_POSIX_ERROR
For example MBED_DEFINE_POSIX_ERROR( EPERM, EPERM ). This macro defines the following values:
ERROR_CODE_EPERM = MBED_POSIX_ERROR_BASE+EPERM
ERROR_EPERM = -(MBED_POSIX_ERROR_BASE+EPERM)
Its effectively equivalent to:
ERROR_CODE_EPERM = 1
ERROR_EPERM = -1
All POSIX error codes currently supported by MbedOS(defined in mbed_retarget.h) are defined using the MBED_DEFINE_POSIX_ERROR macro.

Below are the POSIX error codes and the description:

    EPERM                      1        Operation not permitted
    ENOENT                     2        No such file or directory
    ESRCH                      3        No such process
    EINTR                      4        Interrupted system call
    EIO                        5        I/O error
    ENXIO                      6        No such device or address
    E2BIG                      7        Argument list too long
    ENOEXEC                    8        Exec format error
    EBADF                      9        Bad file number
    ECHILD                     10       No child processes
    EAGAIN                     11       Try again
    ENOMEM                     12       Out of memory
    EACCES                     13       Permission denied
    EFAULT                     14       Bad address
    ENOTBLK                    15       Block device required
    EBUSY                      16       Device or resource busy
    EEXIST                     17       File exists
    EXDEV                      18       Cross-device link
    ENODEV                     19       No such device
    ENOTDIR                    20       Not a directory
    EISDIR                     21       Is a directory
    EINVAL                     22       Invalid argument
    ENFILE                     23       File table overflow
    EMFILE                     24       Too many open files
    ENOTTY                     25       Not a typewriter
    ETXTBSY                    26       Text file busy
    EFBIG                      27       File too large
    ENOSPC                     28       No space left on device
    ESPIPE                     29       Illegal seek
    EROFS                      30       Read-only file system
    EMLINK                     31       Too many links
    EPIPE                      32       Broken pipe
    EDOM                       33       Math argument out of domain of func
    ERANGE                     34       Math result not representable
    EDEADLK                    35       Resource deadlock would occur
    ENAMETOOLONG               36       File name too long
    ENOLCK                     37       No record locks available
    ENOSYS                     38       Function not implemented
    ENOTEMPTY                  39       Directory not empty
    ELOOP                      40       Too many symbolic links encountered
    EWOULDBLOCK                EAGAIN   Operation would block
    ENOMSG                     42       No message of desired type
    EIDRM                      43       Identifier removed
    ECHRNG                     44       Channel number out of range
    EL2NSYNC                   45       Level 2 not synchronized
    EL3HLT                     46       Level 3 halted
    EL3RST                     47       Level 3 reset
    ELNRNG                     48       Link number out of range
    EUNATCH                    49       Protocol driver not attached
    ENOCSI                     50       No CSI structure available
    EL2HLT                     51       Level 2 halted
    EBADE                      52       Invalid exchange
    EBADR                      53       Invalid request descriptor
    EXFULL                     54       Exchange full
    ENOANO                     55       No anode
    EBADRQC                    56       Invalid request code
    EBADSLT                    57       Invalid slot
    EDEADLOCK                  EDEADLK  Resource deadlock would occur
    EBFONT                     59       Bad font file format
    ENOSTR                     60       Device not a stream
    ENODATA                    61       No data available
    ETIME                      62       Timer expired
    ENOSR                      63       Out of streams resources
    ENONET                     64       Machine is not on the network
    ENOPKG                     65       Package not installed
    EREMOTE                    66       Object is remote
    ENOLINK                    67       Link has been severed
    EADV                       68       Advertise error
    ESRMNT                     69       Srmount error
    ECOMM                      70       Communication error on send
    EPROTO                     71       Protocol error
    EMULTIHOP                  72       Multihop attempted
    EDOTDOT                    73       RFS specific error
    EBADMSG                    74       Not a data message
    EOVERFLOW                  75       Value too large for defined data type
    ENOTUNIQ                   76       Name not unique on network
    EBADFD                     77       File descriptor in bad state
    EREMCHG                    78       Remote address changed
    ELIBACC                    79       Can not access a needed shared library
    ELIBBAD                    80       Accessing a corrupted shared library
    ELIBSCN                    81       .lib section in a.out corrupted
    ELIBMAX                    82       Attempting to link in too many shared libraries
    ELIBEXEC                   83       Cannot exec a shared library directly
    EILSEQ                     84       Illegal byte sequence
    ERESTART                   85       Interrupted system call should be restarted
    ESTRPIPE                   86       Streams pipe error
    EUSERS                     87       Too many users
    ENOTSOCK                   88       Socket operation on non-socket
    EDESTADDRREQ               89       Destination address required
    EMSGSIZE                   90       Message too long
    EPROTOTYPE                 91       Protocol wrong type for socket
    ENOPROTOOPT                92       Protocol not available
    EPROTONOSUPPORT            93       Protocol not supported
    ESOCKTNOSUPPORT            94       Socket type not supported
    EOPNOTSUPP                 95       Operation not supported on transport endpoint
    EPFNOSUPPORT               96       Protocol family not supported
    EAFNOSUPPORT               97       Address family not supported by protocol
    EADDRINUSE                 98       Address already in use
    EADDRNOTAVAIL              99       Cannot assign requested address
    ENETDOWN                   100      Network is down
    ENETUNREACH                101      Network is unreachable
    ENETRESET                  102      Network dropped connection because of reset
    ECONNABORTED               103      Software caused connection abort
    ECONNRESET                 104      Connection reset by peer
    ENOBUFS                    105      No buffer space available
    EISCONN                    106      Transport endpoint is already connected
    ENOTCONN                   107      Transport endpoint is not connected
    ESHUTDOWN                  108      Cannot send after transport endpoint shutdown
    ETOOMANYREFS               109      Too many references: cannot splice
    ETIMEDOUT                  110      Connection timed out
    ECONNREFUSED               111      Connection refused
    EHOSTDOWN                  112      Host is down
    EHOSTUNREACH               113      No route to host
    EALREADY                   114      Operation already in progress
    EINPROGRESS                115      Operation now in progress
    ESTALE                     116      Stale NFS file handle
    EUCLEAN                    117      Structure needs cleaning
    ENOTNAM                    118      Not a XENIX named type file
    ENAVAIL                    119      No XENIX semaphores available
    EISNAM                     120      Is a named type file
    EREMOTEIO                  121      Remote I/O error
    EDQUOT                     122      Quota exceeded
    ENOMEDIUM                  123      No medium found
    EMEDIUMTYPE                124      Wrong medium type
    ECANCELED                  125      Operation Canceled
    ENOKEY                     126      Required key not available
    EKEYEXPIRED                127      Key has expired
    EKEYREVOKED                128      Key has been revoked
    EKEYREJECTED               129      Key was rejected by service
    EOWNERDEAD                 130      Owner died
    ENOTRECOVERABLE            131      State not recoverable
    
Note:
MbedOS System Error codes are defined using the macro MBED_DEFINE_SYSTEM_ERROR
For example MBED_DEFINE_SYSTEM_ERROR( INVALID_ARGUMENT ,1 ) macro defines the following values:
ERROR_CODE_INVALID_ARGUMENT = MBED_SYSTEM_ERROR_BASE+1
ERROR_INVALID_ARGUMENT = MAKE_MBED_ERROR(ERROR_TYPE_SYSTEM, MBED_MODULE_UNKNOWN, ERROR_CODE_INVALID_ARGUMENT)
Its effectively equivalent to:
ERROR_CODE_INVALID_ARGUMENT = 1
ERROR_INVALID_ARGUMENT = 0x80FF0001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN) New System Error codes should be defined using MBED_DEFINE_SYSTEM_ERROR macro and must have an unique error code value
passed as the second argument in the MBED_DEFINE_SYSTEM_ERROR macro.

Below are the Mbed System error codes and the description:
    UNKNOWN                    256      Unknown error
    INVALID_ARGUMENT           257      Invalid Argument
    INVALID_DATA               258      Invalid data
    INVALID_FORMAT             259      Invalid format
    INVALID_INDEX              260      Invalid Index
    INVALID_SIZE               261      Invalid Size
    INVALID_OPERATION          262      Invalid Operation
    NOT_FOUND                  263      Not Found
    ACCESS_DENIED              264      Access Denied
    NOT_SUPPORTED              265      Not supported
    BUFFER_FULL                266      Buffer Full
    MEDIA_FULL                 267      Media/Disk Full
    ALREADY_IN_USE             268      Already in use
    TIMEOUT                    269      Timeout error
    NOT_READY                  270      Not Ready
    FAILED_OPERATION           271      Requested Operation failed
    OPERATION_PROHIBITED       272      Operation prohibited
    OPERATION_ABORTED          273      Operation failed
    WRITE_PROTECTED            274      Attempt to write to write-protected resource
    NO_RESPONSE                275      No response
    SEMAPHORE_LOCK_FAILED      276      Semaphore lock failed
    MUTEX_LOCK_FAILED          277      Mutex lock failed
    SEMAPHORE_UNLOCK_FAILED    278      Semaphore unlock failed
    MUTEX_UNLOCK_FAILED        279      Mutex unlock failed
    CRC_ERROR                  280      CRC error or mismatch
    OPEN_FAILED                281      Open failed
    CLOSE_FAILED               282      Close failed
    READ_FAILED                283      Read failed
    WRITE_FAILED               284      Write failed
    INITIALIZATION_FAILED      285      Initialization failed
    BOOT_FAILURE               286      Boot failure
    OUT_OF_MEMORY              287      Out of memory
    OUT_OF_RESOURCES           288      Out of resources
    ALLOC_FAILED               289      Alloc failed
    FREE_FAILED                290      Free failed
    OVERFLOW                   291      Overflow error
    UNDERFLOW                  292      Underflow error
    STACK_OVERFLOW             293      Stack overflow error
    ISR_QUEUE_OVERFLOW         294      ISR queue overflow
    TIMER_QUEUE_OVERFLOW       295      Timer Queue overflow
    CLIB_SPACE_UNAVAILABLE     296      Standard library error - Space unavailable
    CLIB_EXCEPTION             297      Standard library error - Exception
    CLIB_MUTEX_INIT_FAILURE    298      Standard library error - Mutex Init failure
    CREATE_FAILED              299      Create failed
    DELETE_FAILED              300      Delete failed
    THREAD_CREATE_FAILED       301      Thread Create failed
    THREAD_DELETE_FAILED       302      Thread Delete failed
    PROHIBITED_IN_ISR_CONTEXT  303      Operation Prohibited in ISR context
    PINMAP_INVALID             304      Pinmap Invalid
    RTOS_EVENT                 305      Unknown Rtos Error
    RTOS_THREAD_EVENT          306      Rtos Thread Error
    RTOS_MUTEX_EVENT           307      Rtos Mutex Error
    RTOS_SEMAPHORE_EVENT       308      Rtos Semaphore Error
    RTOS_MEMORY_POOL_EVENT     309      Rtos Memory Pool Error
    RTOS_TIMER_EVENT           310      Rtos Timer Error
    RTOS_EVENT_FLAGS_EVENT     311      Rtos Event flags Error
    RTOS_MESSAGE_QUEUE_EVENT   312      Rtos Message queue Error
    DEVICE_BUSY                313      Device Busy
    CONFIG_UNSUPPORTED         314      Configuration not supported
    CONFIG_MISMATCH            315      Configuration mismatch
    ALREADY_INITIALIZED        316      Already initialized
    HARDFAULT_EXCEPTION        317      HardFault exception
    MEMMANAGE_EXCEPTION        318      MemManage exception
    BUSFAULT_EXCEPTION         319      BusFault exception
    USAGEFAULT_EXCEPTION       320      UsageFault exception
    BLE_NO_FRAME_INITIALIZED,  321      BLE No frame initialized
    BLE_BACKEND_CREATION_FAILED 322     BLE Backend creation failed
    BLE_BACKEND_NOT_INITIALIZED 323     BLE Backend not initialized
    ASSERTION_FAILED           324      Assertion Failed
    AUTHENTICATION_FAILED      325      Authentication Failed
    RBP_AUTHENTICATION_FAILED  326      Rollback Protect Authentication Failed
    
Custom Error codes can be defined using the macro DEFINE_CUSTOM_ERROR
This is mainly meant to capture non-generic error codes specific to a device. For example DEFINE_CUSTOM_ERROR( MY_CUSTOM_ERROR ,1 ) macro defines the following values:
ERROR_CODE_MY_CUSTOM_ERROR = MBED_CUSTOM_ERROR_BASE+1
ERROR_MY_CUSTOM_ERROR = MAKE_MBED_ERROR(ERROR_TYPE_CUSTOM, MBED_MODULE_UNKNOWN, ERROR_CODE_MY_CUSTOM_ERROR)
Its effectively equivalent to:
ERROR_CODE_MY_CUSTOM_ERROR = 4097
ERROR_MY_CUSTOM_ERROR = 0xA0FF1001
(Note that MODULE field is set to MBED_MODULE_UNKNOWN)

**Using error codes:**
POSIX error codes may be used in modules/functions currently using POSIX error codes and switching them to Mbed-OS error codes may cause interoperability issues. For example, some of the filesystem, network stack implementations may need to use POSIX error codes in order to keep them compatible with other modules interfacing with them, and may continue to use POSIX error codes.

In all other cases, like for any native development of Mbed-OS modules Mbed-OS error codes should be used. This makes it easy to use Mbed-OS error reporting/logging infrastructure and makes debugging error scenarios much more efficient.

Note:
**Searching for error codes in mbed-os source tree:**
If you get an error report as below which you want to search for in mbed-os source tree, first take note of "Error Code" number.
For example, the below error report has an error code of 259. Find the error name associated with the error code and in this case its INVALID_FORMAT.
Use that error name(INVALID_FORMAT) to search the source tree for code locations setting that specific error code.
If the Error module reported is not 255(which indicates unknown module), you can also use that to narrow down to the specific component reporting the error. See mbed_module_type_t enum above for module mapping.
    ++ MbedOS Error Info ++
    Error Status: 0x80FF013D Code: 317 Module: 255
    Error Message: Fault exception
    Location: 0x5CD1
    Error Value: 0x4A2A
    Current Thread: Id: 0x20001E80 Entry: 0x5EB1 StackSize: 0x1000 StackMem: 0x20000E80 SP: 0x2002FF90
    For more info, visit: https://mbed.com/s/error?error=0x80FF013D&mbedos=999999&core=0x410FC241&compile=1&ver=5060528
    -- MbedOS Error Info --
    

Definition at line 583 of file platform/mbed_error.h.

mbed_error_type_t definition

Note:
This enumeration defines the Error types supported. The value of these enum values will be encoded into mbed_error_status_t TYPE field.
See mbed_error_status_t description for more info.
MBED_ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.
MBED_ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.
MBED_ERROR_TYPE_POSIX - Used to indicate that the error status is of POSIX error type.

Definition at line 208 of file platform/mbed_error.h.

mbed_error_type_t definition

Note:
This enumeration defines the Error types supported. The value of these enum values will be encoded into mbed_error_status_t TYPE field.
See mbed_error_status_t description for more info.
MBED_ERROR_TYPE_SYSTEM - Used to indicate that the error status is of System defined Error type.
MBED_ERROR_TYPE_CUSTOM - Used to indicate that the error status is of Custom defined Error type.
MBED_ERROR_TYPE_POSIX - Used to indicate that the error status is of POSIX error type.

Definition at line 208 of file cmsis/BUILD/mbed/platform/mbed_error.h.

mbed_module_type_t definition

Note:
This enumeration defines the module types. The value of these enum values will be encoded into mbed_error_status_t MODULE field.

See mbed_error_status_t description for more info.
MBED_MODULE_UNKNOWN - This module type can be used if caller of the mbed_error/mbed_warning doesn't know who is the actual originator of the error.
Other module values can be used to provide more info on who/where the error originated from.

For example, if I2C driver is the component originating the error you can use MBED_MODULE_DRIVER_I2C to provide more info.
Its used in call to MBED_MAKE_ERROR/MBED_MAKE_SYSTEM_ERROR/MBED_MAKE_CUSTOM_ERROR macros.
      Example: mbed_error_status_t i2c_driver_error = MBED_MAKE_ERROR( MBED_MODULE_DRIVER_I2C, MBED_ERROR_CONFIG_UNSUPPORTED );
Note:

Below are the module code mappings:
    MBED_MODULE_APPLICATION                     0       Application
    MBED_MODULE_PLATFORM                        1       Platform
    MBED_MODULE_KERNEL                          2       RTX Kernel
    MBED_MODULE_NETWORK_STACK                   3       Network stack
    MBED_MODULE_HAL                             4       HAL - Hardware Abstraction Layer
    MBED_MODULE_MEMORY_SUBSYSTEM                5       Memory Subsystem
    MBED_MODULE_FILESYSTEM                      6       Filesystem
    MBED_MODULE_BLOCK_DEVICE                    7       Block device
    MBED_MODULE_DRIVER                          8       Driver
    MBED_MODULE_DRIVER_SERIAL                   9       Serial Driver
    MBED_MODULE_DRIVER_RTC                      10      RTC Driver
    MBED_MODULE_DRIVER_I2C                      11      I2C Driver
    MBED_MODULE_DRIVER_SPI                      12      SPI Driver
    MBED_MODULE_DRIVER_GPIO                     13      GPIO Driver
    MBED_MODULE_DRIVER_ANALOG                   14      Analog Driver
    MBED_MODULE_DRIVER_DIGITAL                  15      DigitalIO Driver
    MBED_MODULE_DRIVER_CAN                      16      CAN Driver
    MBED_MODULE_DRIVER_ETHERNET                 17      Ethernet Driver
    MBED_MODULE_DRIVER_CRC                      18      CRC Module
    MBED_MODULE_DRIVER_PWM                      19      PWM Driver
    MBED_MODULE_DRIVER_QSPI                     20      QSPI Driver
    MBED_MODULE_DRIVER_USB                      21      USB Driver
    MBED_MODULE_TARGET_SDK                      22      SDK
    MBED_MODULE_BLE                             23      BLE
    MBED_MODULE_NETWORK_STATS                   24      Network Statistics

    MBED_MODULE_UNKNOWN                         255     Unknown module
    

Definition at line 264 of file cmsis/BUILD/mbed/platform/mbed_error.h.

mbed_module_type_t definition

Note:
This enumeration defines the module types. The value of these enum values will be encoded into mbed_error_status_t MODULE field.

See mbed_error_status_t description for more info.
MBED_MODULE_UNKNOWN - This module type can be used if caller of the mbed_error/mbed_warning doesn't know who is the actual originator of the error.
Other module values can be used to provide more info on who/where the error originated from.

For example, if I2C driver is the component originating the error you can use MBED_MODULE_DRIVER_I2C to provide more info.
Its used in call to MBED_MAKE_ERROR/MBED_MAKE_SYSTEM_ERROR/MBED_MAKE_CUSTOM_ERROR macros.
      Example: mbed_error_status_t i2c_driver_error = MBED_MAKE_ERROR( MBED_MODULE_DRIVER_I2C, MBED_ERROR_CONFIG_UNSUPPORTED );
Note:

Below are the module code mappings:
    MBED_MODULE_APPLICATION                     0       Application
    MBED_MODULE_PLATFORM                        1       Platform
    MBED_MODULE_KERNEL                          2       RTX Kernel
    MBED_MODULE_NETWORK_STACK                   3       Network stack
    MBED_MODULE_HAL                             4       HAL - Hardware Abstraction Layer
    MBED_MODULE_MEMORY_SUBSYSTEM                5       Memory Subsystem
    MBED_MODULE_FILESYSTEM                      6       Filesystem
    MBED_MODULE_BLOCK_DEVICE                    7       Block device
    MBED_MODULE_DRIVER                          8       Driver
    MBED_MODULE_DRIVER_SERIAL                   9       Serial Driver
    MBED_MODULE_DRIVER_RTC                      10      RTC Driver
    MBED_MODULE_DRIVER_I2C                      11      I2C Driver
    MBED_MODULE_DRIVER_SPI                      12      SPI Driver
    MBED_MODULE_DRIVER_GPIO                     13      GPIO Driver
    MBED_MODULE_DRIVER_ANALOG                   14      Analog Driver
    MBED_MODULE_DRIVER_DIGITAL                  15      DigitalIO Driver
    MBED_MODULE_DRIVER_CAN                      16      CAN Driver
    MBED_MODULE_DRIVER_ETHERNET                 17      Ethernet Driver
    MBED_MODULE_DRIVER_CRC                      18      CRC Module
    MBED_MODULE_DRIVER_PWM                      19      PWM Driver
    MBED_MODULE_DRIVER_QSPI                     20      QSPI Driver
    MBED_MODULE_DRIVER_USB                      21      USB Driver
    MBED_MODULE_TARGET_SDK                      22      SDK
    MBED_MODULE_BLE                             23      BLE
    MBED_MODULE_NETWORK_STATS                   24      Network Statistics

    MBED_MODULE_UNKNOWN                         255     Unknown module
    

Definition at line 264 of file platform/mbed_error.h.


Function Documentation

MBED_NORETURN void error ( const char *  format,
  ... 
)

To generate a fatal compile-time error, you can use the pre-processor error directive.

Parameters:
formatC string that contains data stream to be printed. Code snippets below show valid format.
 #error "That shouldn't have happened!"

If the compiler evaluates this line, it will report the error and stop the compile.

For example, you could use this to check some user-defined compile-time variables:

 #define NUM_PORTS 7
 #if (NUM_PORTS > 4)
     #error "NUM_PORTS must be less than 4"
 #endif

Reporting Run-Time Errors: To generate a fatal run-time error, you can use the mbed error() function.

 error("That shouldn't have happened!");

If the mbed running the program executes this function, it will print the message via the USB serial port, and then die with the blue lights of death!

The message can use printf-style formatting, so you can report variables in the message too. For example, you could use this to check a run-time condition:

 if(x >= 5) {
     error("expected x to be less than 5, but got %d", x);
 }
mbed_error_status_t mbed_clear_all_errors ( void   )

Clears the last error, first error, error count and all entries in the error history.

Returns:
0 or MBED_SUCCESS on success.

Clears the last error, first error, error count and all entries in the error history.

Returns:
0 or MBED_SUCCESS on success.

Definition at line 416 of file mbed_error.c.

MBED_NORETURN mbed_error_status_t mbed_error ( mbed_error_status_t  error_status,
const char *  error_msg,
unsigned int  error_value,
const char *  filename,
int  line_number 
)

Call this function to set a fatal system error and halt the system.

This function will log the fatal error with the context info and prints the error report and halts the system.

Parameters:
error_statusmbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
error_msgThe error message to be printed out to STDIO/Serial.
error_valueValue associated with the error status. This would depend on error code/error scenario.
filenameName of the source file originating the error( Most callers can pass __FILE__ here ).
line_numberThe line number of the source file originating the error( Most callers can pass __LINE__ here ) .
Returns:
Does not return.
 mbed_error( MBED_ERROR_PROHIBITED_OPERATION, "Prohibited operation tried", 0, __FILE__, __LINE__ )
Note:
See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API

Definition at line 265 of file mbed_error.c.

mbed_error_status_t mbed_error_initialize ( void   )

Initialize error handling system, this is called by the mbed-os boot sequence.

This is not required to be called by Application unless the boot sequence is overridden by the system implementation. NOTE: If MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled and if the current reboot count exceeds MBED_CONF_PLATFORM_ERROR_REBOOT_MAX the system will halt when this function is called, and in such cases the caller will not get the control back. Also note that calling this function may trigger mbed_error_reboot_callback() if application side overides mbed_error_reboot_callback().

Returns:
MBED_SUCCESS on success.

Definition at line 202 of file mbed_error.c.

void mbed_error_reboot_callback ( mbed_error_ctx error_context )

Callback function for reporting error context during boot up.

When MbedOS error handling system detects a fatal error it will auto-reboot the system(if MBED_CONF_PLATFORM_FATAL_ERROR_AUTO_REBOOT_ENABLED is enabled) after capturing the error info in special crash data RAM region. Once rebooted, MbedOS initialization routines will call this function with a pointer to the captured mbed_error_ctx structure. If application implementation needs to receive this callback, mbed_error_reboot_callback function should be overridden with custom implementation. By default it's defined as a WEAK function in mbed_error.c. Note that this callback will be invoked before the system starts executing main() function. So the implementation of the callback should be aware any resource limitations/availability of resources which are yet to be initialized by application main().

Parameters:
error_ctxError context structure associated with this error.
Returns:
void

Definition at line 196 of file mbed_error.c.

int mbed_get_error_count ( void   )

Returns the number of system errors reported after boot.

Returns:
int Number of errors reported.

Definition at line 252 of file mbed_error.c.

int mbed_get_error_hist_count ( void   )

Returns the current number of entries in the error history, if there has been more than max number of errors logged the number returned will be max depth of error history.

Returns:
Current number of entries in the error history.

Definition at line 555 of file mbed_error.c.

mbed_error_status_t mbed_get_error_hist_info ( int  index,
mbed_error_ctx error_info 
)

Reads the error context information for a specific error from error history, specified by the index.

Parameters:
indexindex of the error context entry in the history to be retrieved.
The number of entries in the error history is configured during build and the max index depends on max depth of error history.
index = 0 points to the oldest entry in the history, and index = (max history depth - 1) points to the latest entry in the error history.
error_infoThis is the mbed_error_context info captured as part of the error history. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
Returns:
0 or MBED_SUCCESS on success. MBED_ERROR_INVALID_ARGUMENT in case of invalid index

Definition at line 549 of file mbed_error.c.

mbed_error_status_t mbed_get_first_error ( void   )

Returns the first system error reported.

Returns:
mbed_error_status_t code logged for the first error or MBED_SUCCESS if no errors are logged.

Definition at line 238 of file mbed_error.c.

mbed_error_status_t mbed_get_first_error_info ( mbed_error_ctx error_info )

Reads the first error context information captured.

Parameters:
error_infoThis is the mbed_error_context info captured as part of the first mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
Returns:
0 or MBED_SUCCESS on success. MBED_ERROR_INVALID_ARGUMENT in case of invalid index

Definition at line 368 of file mbed_error.c.

mbed_error_status_t mbed_get_last_error ( void   )

Returns the most recent system error reported.

Returns:
mbed_error_status_t code logged for the last error or MBED_SUCCESS if no errors are logged.

Definition at line 245 of file mbed_error.c.

mbed_error_status_t mbed_get_last_error_info ( mbed_error_ctx error_info )

Reads the last error context information captured.

Parameters:
error_infoThis is the mbed_error_context info captured as part of the last mbed_error call. The caller should pass a pointer to mbed_error_context struct allocated by the caller.
Returns:
0 or MBED_ERROR_SUCCESS on success. MBED_ERROR_INVALID_ARGUMENT in case of invalid index

Definition at line 375 of file mbed_error.c.

mbed_error_status_t mbed_get_reboot_error_info ( mbed_error_ctx error_info )

Call this function to retrieve the error context after a fatal error which triggered a system reboot.

The function retrieves the error context stored in crash-report ram area which is preserved over reboot.

Parameters:
error_infoPointer to mbed_error_ctx struct allocated by the caller. This is the mbed_error_ctx info captured as part of the fatal error which triggered the reboot.
Returns:
0 or MBED_SUCCESS on success. MBED_ERROR_INVALID_ARGUMENT in case of invalid error_info pointer MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system

Definition at line 351 of file mbed_error.c.

mbed_error_status_t mbed_make_error ( mbed_error_type_t  error_type,
mbed_module_type_t  module,
mbed_error_code_t  error_code 
)

Generates a mbed_error_status_t value based on passed in values for type, module and error code.

Parameters:
error_typeError type based on mbed_error_type_t enum.
moduleModule type based on mbed_module_type_t enum.
error_codeError codes defined by mbed_error_code_t enum
Returns:
0 or MBED_ERROR_SUCCESS on success.

Definition at line 382 of file mbed_error.c.

mbed_error_status_t mbed_reset_reboot_count ( void   )

Calling this function resets the current reboot count stored as part of error context captured in special crash data RAM region.

The function will also update the CRC value stored as part of error context accordingly.

Returns:
MBED_SUCCESS on success. MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system

Definition at line 333 of file mbed_error.c.

mbed_error_status_t mbed_reset_reboot_error_info ( void   )

Calling this function resets the current reboot context captured by the system(stored in special crash data RAM region).

Returns:
MBED_SUCCESS on success. MBED_ERROR_ITEM_NOT_FOUND if no reboot context is currently captured by the system

Definition at line 321 of file mbed_error.c.

mbed_error_status_t mbed_save_error_hist ( const char *  path )

Saves the error history information to a file.

Parameters:
pathpath to the file in the filesystem
Returns:
0 or MBED_ERROR_SUCCESS on success. MBED_ERROR_WRITE_FAILED if writing to file failed MBED_ERROR_INVALID_ARGUMENT if path is not valid
Note:
Filesystem support is required in order for this function to work.

Definition at line 560 of file mbed_error.c.

mbed_error_status_t mbed_set_error_hook ( mbed_error_hook_t  custom_error_hook )

Registers an application defined error callback with the error handling system.

This function will be called with error context info whenever system handles a mbed_error/mbed_warning call NOTE: This function should be implemented for re-entrancy as multiple threads may invoke mbed_error which may cause error hook to be called.

Parameters:
custom_error_hookmbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
Returns:
0 or MBED_SUCCESS on success. MBED_ERROR_INVALID_ARGUMENT in case of NULL for custom_error_hook
 mbed_error_status_t my_custom_error_hook(mbed_error_status_t error_status, const mbed_error_ctx *error_ctx) {
    //Do something with the error_status or error_ctx
 }

 mbed_set_error_hook( my_custom_error_hook )
Note:
The erro hook function implementation should be re-entrant.

Definition at line 309 of file mbed_error.c.

mbed_error_status_t mbed_warning ( mbed_error_status_t  error_status,
const char *  error_msg,
unsigned int  error_value,
const char *  filename,
int  line_number 
)

Call this function to set a system error/warning.

This function will log the error status with the context info and return to caller.

Parameters:
error_statusmbed_error_status_t status to be set(See mbed_error_status_t enum above for available error status values).
error_msgThe error message to be printed out to STDIO/Serial.
error_valueValue associated with the error status. This would depend on error code/error scenario.
filenameName of the source file originating the error( Most callers can pass __FILE__ here ).
line_numberThe line number of the source file originating the error( Most callers can pass __LINE__ here ) .
Returns:
0 or MBED_SUCCESS. MBED_ERROR_INVALID_ARGUMENT if called with invalid error status/codes
 mbed_error( ERROR_OUT_OF_MEMORY, "Out of memory error", 0, __FILE__, __LINE__ )
Note:
See MBED_WARNING/MBED_ERROR macros which provides a wrapper on this API

Definition at line 259 of file mbed_error.c.