ESP32 define custom esp_err_t errors and best practice

fiveowle5
Posts: 2
Joined: Tue Dec 03, 2019 4:16 pm

ESP32 define custom esp_err_t errors and best practice

Postby fiveowle5 » Thu Jan 09, 2020 1:10 pm

Hello all,

Is it possible to define custom esp_err_t types in addition to the existing esp errors?

I can see the definition of the esp error codes in some header files. It defines an error base + the unique error number as hex.
For instance in esp_ota_ops.h:

Code: Select all

#define ESP_ERR_OTA_BASE                         0x1500                     /*!< Base error code for ota_ops api */
#define ESP_ERR_OTA_PARTITION_CONFLICT           (ESP_ERR_OTA_BASE + 0x01)  /*!< Error if request was to write or erase the current running partition */
Is it possible to add my custom errors in my components header files in addition with the existing ones? If yes how to ensure that the error base does not exist and will not be in conflict by incoming ESP-IDF Updates?

If adding custom esp_err_t types is not possible what is the best practice to return ESP error codes and my own defined error codes from my functions?

Thanks

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: ESP32 define custom esp_err_t errors and best practice

Postby ESP_Angus » Fri Jan 10, 2020 4:37 am

Hi fiveowle,

I'm afraid we don't have a good solution for this yet. We have discussed adding a "user" reserved range where, but other people also publish IDF components to be shared and it's not helpful if someone publishes a thirdparty component that also uses codes in the "user" range.

We are looking into a better solution to apply in the future.

For now, my recommendation would be:
  • If you can use only the existing built-in esp_err_t error values, return esp_err_t. BTW, if there is some reasonably generic error that you think we've missed out, feel free to make a feature request to add it.
  • If your API needs more specific errors, create a totally new enum type for its result values.
Angus

boarchuz
Posts: 559
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32 define custom esp_err_t errors and best practice

Postby boarchuz » Fri Jan 10, 2020 7:22 am

I had the exact same query as fiveowle5.
ESP_Angus wrote:
Fri Jan 10, 2020 4:37 am
If you can use only the existing built-in esp_err_t error values, return esp_err_t. BTW, if there is some reasonably generic error that you think we've missed out, feel free to make a feature request to add it.
https://docs.espressif.com/projects/esp ... codes.html
It seems there aren't all that many pre-defined, and a lot of potentially useful ones have component-specific prefixes which would make them awkward to use.

Would you be open to adding a whole bunch of them or is there a preference for keeping a limited number of vague ones?

Some that spring to mind just now:
  • NOT_CONFIGURED
  • NOT_INITIALIZED
  • NOT_READY
  • NOT_STARTED
  • NOT_STOPPED
  • BUSY / ACTIVE / IN_PROGRESS
  • IDLE
  • END / CANCEL / ABORT
  • COMPLETED
  • IGNORE
  • REPEAT / RETRY / AGAIN
  • WAIT
  • PENDING
  • RESET
  • DISCONNECTED
  • NOT_RESPONDING / NO_RESPONSE
  • READ_ONLY / PROTECTED
  • NOT_ALLOWED / DENIED / FORBIDDEN / NOT_AUTHORIZED
  • NOT_REGISTERED
  • DISABLED
  • EXPIRED
  • REMOVED
  • NOT_IMPLEMENTED
  • NOT_FOUND
  • NULL
  • MISMATCH
  • DUPLICATE / EXISTS
  • UNDEFINED
  • OUT_OF_RANGE
  • CONFLICT
  • FULL
  • EMPTY
  • INSUFFICIENT
  • EXCEEDED
  • STATE
  • MODE
  • METHOD
  • SIZE
  • LENGTH
  • NAME
  • KEY
  • VALUE
  • ENCODING
  • FORMAT
  • PROTOCOL
  • UNRECOGNIZED / UNKNOWN

fiveowle5
Posts: 2
Joined: Tue Dec 03, 2019 4:16 pm

Re: ESP32 define custom esp_err_t errors and best practice

Postby fiveowle5 » Tue Jan 14, 2020 9:12 am

Thanks for your responses. In that case I will implement my own enums.

NotMyRealName
Posts: 36
Joined: Thu Feb 13, 2020 1:35 am

Re: ESP32 define custom esp_err_t errors and best practice

Postby NotMyRealName » Thu Mar 10, 2022 3:55 am

I realize this is an old post but I don't think the situation has changed much?

There doesn't seem to be any overlap with standard errno definitions so I've defined the following for my project:

Code: Select all


#define ESP_ERR_ERRNO_BASE (0)

#define ESP_ERR_EPERM (1 + ESP_ERR_ERRNO_BASE)                  /*!< Not owner */
#define ESP_ERR_ENOENT (2 + ESP_ERR_ERRNO_BASE)                 /*!< No such file or directory */
#define ESP_ERR_ESRCH (3 + ESP_ERR_ERRNO_BASE)                  /*!< No such process */
#define ESP_ERR_EINTR (4 + ESP_ERR_ERRNO_BASE)                  /*!< Interrupted system call */
#define ESP_ERR_EIO (5 + ESP_ERR_ERRNO_BASE)                    /*!< I/O error */
#define ESP_ERR_ENXIO (6 + ESP_ERR_ERRNO_BASE)                  /*!< No such device or address */
#define ESP_ERR_E2BIG (7 + ESP_ERR_ERRNO_BASE)                  /*!< Arg list too long */
#define ESP_ERR_ENOEXEC (8 + ESP_ERR_ERRNO_BASE)                /*!< Exec format error */
#define ESP_ERR_EBADF (9 + ESP_ERR_ERRNO_BASE)                  /*!< Bad file number */
#define ESP_ERR_ECHILD (10 + ESP_ERR_ERRNO_BASE)                /*!< No children */
#define ESP_ERR_EAGAIN (11 + ESP_ERR_ERRNO_BASE)                /*!< No more processes */
#define ESP_ERR_ENOMEM (12 + ESP_ERR_ERRNO_BASE)                /*!< Not enough space */
#define ESP_ERR_EACCES (13 + ESP_ERR_ERRNO_BASE)                /*!< Permission denied */
#define ESP_ERR_EFAULT (14 + ESP_ERR_ERRNO_BASE)                /*!< Bad address */
#define ESP_ERR_ENOTBLK (15 + ESP_ERR_ERRNO_BASE)               /*!< Block device required */
#define ESP_ERR_EBUSY (16 + ESP_ERR_ERRNO_BASE)                 /*!< Device or resource busy */
#define ESP_ERR_EEXIST (17 + ESP_ERR_ERRNO_BASE)                /*!< File exists */
#define ESP_ERR_EXDEV (18 + ESP_ERR_ERRNO_BASE)                 /*!< Cross-device link */
#define ESP_ERR_ENODEV (19 + ESP_ERR_ERRNO_BASE)                /*!< No such device */
#define ESP_ERR_ENOTDIR (20 + ESP_ERR_ERRNO_BASE)               /*!< Not a directory */
#define ESP_ERR_EISDIR (21 + ESP_ERR_ERRNO_BASE)                /*!< Is a directory */
#define ESP_ERR_EINVAL (22 + ESP_ERR_ERRNO_BASE)                /*!< Invalid argument */
#define ESP_ERR_ENFILE (23 + ESP_ERR_ERRNO_BASE)                /*!< Too many open files in system */
#define ESP_ERR_EMFILE (24 + ESP_ERR_ERRNO_BASE)                /*!< File descriptor value too large */
#define ESP_ERR_ENOTTY (25 + ESP_ERR_ERRNO_BASE)                /*!< Not a character device */
#define ESP_ERR_ETXTBSY (26 + ESP_ERR_ERRNO_BASE)               /*!< Text file busy */
#define ESP_ERR_EFBIG (27 + ESP_ERR_ERRNO_BASE)                 /*!< File too large */
#define ESP_ERR_ENOSPC (28 + ESP_ERR_ERRNO_BASE)                /*!< No space left on device */
#define ESP_ERR_ESPIPE (29 + ESP_ERR_ERRNO_BASE)                /*!< Illegal seek */
#define ESP_ERR_EROFS (30 + ESP_ERR_ERRNO_BASE)                 /*!< Read-only file system */
#define ESP_ERR_EMLINK (31 + ESP_ERR_ERRNO_BASE)                /*!< Too many links */
#define ESP_ERR_EPIPE (32 + ESP_ERR_ERRNO_BASE)                 /*!< Broken pipe */
#define ESP_ERR_EDOM (33 + ESP_ERR_ERRNO_BASE)                  /*!< Mathematics argument out of domain of function */
#define ESP_ERR_ERANGE (34 + ESP_ERR_ERRNO_BASE)                /*!< Result too large */
#define ESP_ERR_ENOMSG (35 + ESP_ERR_ERRNO_BASE)                /*!< No message of desired type */
#define ESP_ERR_EIDRM (36 + ESP_ERR_ERRNO_BASE)                 /*!< Identifier removed */
#define ESP_ERR_ECHRNG (37 + ESP_ERR_ERRNO_BASE)                /*!< Channel number out of range */
#define ESP_ERR_EL2NSYNC (38 + ESP_ERR_ERRNO_BASE)              /*!< Level 2 not synchronized */
#define ESP_ERR_EL3HLT (39 + ESP_ERR_ERRNO_BASE)                /*!< Level 3 halted */
#define ESP_ERR_EL3RST (40 + ESP_ERR_ERRNO_BASE)                /*!< Level 3 reset */
#define ESP_ERR_ELNRNG (41 + ESP_ERR_ERRNO_BASE)                /*!< Link number out of range */
#define ESP_ERR_EUNATCH (42 + ESP_ERR_ERRNO_BASE)               /*!< Protocol driver not attached */
#define ESP_ERR_ENOCSI (43 + ESP_ERR_ERRNO_BASE)                /*!< No CSI structure available */
#define ESP_ERR_EL2HLT (44 + ESP_ERR_ERRNO_BASE)                /*!< Level 2 halted */
#define ESP_ERR_EDEADLK (45 + ESP_ERR_ERRNO_BASE)               /*!< Deadlock */
#define ESP_ERR_ENOLCK (46 + ESP_ERR_ERRNO_BASE)                /*!< No lock */
#define ESP_ERR_EBADE (50 + ESP_ERR_ERRNO_BASE)                 /*!< Invalid exchange */
#define ESP_ERR_EBADR (51 + ESP_ERR_ERRNO_BASE)                 /*!< Invalid request descriptor */
#define ESP_ERR_EXFULL (52 + ESP_ERR_ERRNO_BASE)                /*!< Exchange full */
#define ESP_ERR_ENOANO (53 + ESP_ERR_ERRNO_BASE)                /*!< No anode */
#define ESP_ERR_EBADRQC (54 + ESP_ERR_ERRNO_BASE)               /*!< Invalid request code */
#define ESP_ERR_EBADSLT (55 + ESP_ERR_ERRNO_BASE)               /*!< Invalid slot */
#define ESP_ERR_EDEADLOCK (56 + ESP_ERR_ERRNO_BASE)             /*!< File locking deadlock error */
#define ESP_ERR_EBFONT (57 + ESP_ERR_ERRNO_BASE)                /*!< Bad font file fmt */
#define ESP_ERR_ENOSTR (60 + ESP_ERR_ERRNO_BASE)                /*!< Not a stream */
#define ESP_ERR_ENODATA (61 + ESP_ERR_ERRNO_BASE)               /*!< No data (for no delay io) */
#define ESP_ERR_ETIME (62 + ESP_ERR_ERRNO_BASE)                 /*!< Stream ioctl timeout */
#define ESP_ERR_ENOSR (63 + ESP_ERR_ERRNO_BASE)                 /*!< No stream resources */
#define ESP_ERR_ENONET (64 + ESP_ERR_ERRNO_BASE)                /*!< Machine is not on the network */
#define ESP_ERR_ENOPKG (65 + ESP_ERR_ERRNO_BASE)                /*!< Package not installed */
#define ESP_ERR_EREMOTE (66 + ESP_ERR_ERRNO_BASE)               /*!< The object is remote */
#define ESP_ERR_ENOLINK (67 + ESP_ERR_ERRNO_BASE)               /*!< Virtual circuit is gone */
#define ESP_ERR_EADV (68 + ESP_ERR_ERRNO_BASE)                  /*!< Advertise error */
#define ESP_ERR_ESRMNT (69 + ESP_ERR_ERRNO_BASE)                /*!< Srmount error */
#define ESP_ERR_ECOMM (70 + ESP_ERR_ERRNO_BASE)                 /*!< Communication error on send */
#define ESP_ERR_EPROTO (71 + ESP_ERR_ERRNO_BASE)                /*!< Protocol error */
#define ESP_ERR_EMULTIHOP (74 + ESP_ERR_ERRNO_BASE)             /*!< Multihop attempted */
#define ESP_ERR_ELBIN (75 + ESP_ERR_ERRNO_BASE)                 /*!< Inode is remote (not really error) */
#define ESP_ERR_EDOTDOT (76 + ESP_ERR_ERRNO_BASE)               /*!< Cross mount point (not really error) */
#define ESP_ERR_EBADMSG (77 + ESP_ERR_ERRNO_BASE)               /*!< Bad message */
#define ESP_ERR_EFTYPE (79 + ESP_ERR_ERRNO_BASE)                /*!< Inappropriate file type or format */
#define ESP_ERR_ENOTUNIQ (80 + ESP_ERR_ERRNO_BASE)              /*!< Given log. name not unique */
#define ESP_ERR_EBADFD (81 + ESP_ERR_ERRNO_BASE)                /*!< f.d. invalid for this operation */
#define ESP_ERR_EREMCHG (82 + ESP_ERR_ERRNO_BASE)               /*!< Remote address changed */
#define ESP_ERR_ELIBACC (83 + ESP_ERR_ERRNO_BASE)               /*!< Can't access a needed shared lib */
#define ESP_ERR_ELIBBAD (84 + ESP_ERR_ERRNO_BASE)               /*!< Accessing a corrupted shared lib */
#define ESP_ERR_ELIBSCN (85 + ESP_ERR_ERRNO_BASE)               /*!< .lib section in a.out corrupted */
#define ESP_ERR_ELIBMAX (86 + ESP_ERR_ERRNO_BASE)               /*!< Attempting to link in too many libs */
#define ESP_ERR_ELIBEXEC (87 + ESP_ERR_ERRNO_BASE)              /*!< Attempting to exec a shared library */
#define ESP_ERR_ENOSYS (88 + ESP_ERR_ERRNO_BASE)                /*!< Function not implemented */
#define ESP_ERR_ENMFILE (89   + ESP_ERR_ERRNO_BASE)             /*!< No more files */
#define ESP_ERR_ENOTEMPTY (90 + ESP_ERR_ERRNO_BASE)             /*!< Directory not empty */
#define ESP_ERR_ENAMETOOLONG (91 + ESP_ERR_ERRNO_BASE)          /*!< File or path name too long */
#define ESP_ERR_ELOOP (92 + ESP_ERR_ERRNO_BASE)                 /*!< Too many symbolic links */
#define ESP_ERR_EOPNOTSUPP (95 + ESP_ERR_ERRNO_BASE)            /*!< Operation not supported on socket */
#define ESP_ERR_EPFNOSUPPORT (96 + ESP_ERR_ERRNO_BASE)          /*!< Protocol family not supported */
#define ESP_ERR_ECONNRESET (104 + ESP_ERR_ERRNO_BASE)           /*!< Connection reset by peer */
#define ESP_ERR_ENOBUFS (105 + ESP_ERR_ERRNO_BASE)              /*!< No buffer space available */
#define ESP_ERR_EAFNOSUPPORT (106 + ESP_ERR_ERRNO_BASE)         /*!< Address family not supported by protocol family */
#define ESP_ERR_EPROTOTYPE (107 + ESP_ERR_ERRNO_BASE)           /*!< Protocol wrong type for socket */
#define ESP_ERR_ENOTSOCK (108 + ESP_ERR_ERRNO_BASE)             /*!< Socket operation on non-socket */
#define ESP_ERR_ENOPROTOOPT (109 + ESP_ERR_ERRNO_BASE)          /*!< Protocol not available */
#define ESP_ERR_ESHUTDOWN (110 + ESP_ERR_ERRNO_BASE)            /*!< Can't send after socket shutdown */
#define ESP_ERR_ECONNREFUSED (111 + ESP_ERR_ERRNO_BASE)         /*!< Connection refused */
#define ESP_ERR_EADDRINUSE (112 + ESP_ERR_ERRNO_BASE)           /*!< Address already in use */
#define ESP_ERR_ECONNABORTED (113 + ESP_ERR_ERRNO_BASE)         /*!< Software caused connection abort */
#define ESP_ERR_ENETUNREACH (114 + ESP_ERR_ERRNO_BASE)          /*!< Network is unreachable */
#define ESP_ERR_ENETDOWN (115 + ESP_ERR_ERRNO_BASE)             /*!< Network interface is not configured */
#define ESP_ERR_ETIMEDOUT (116 + ESP_ERR_ERRNO_BASE)            /*!< Connection timed out */
#define ESP_ERR_EHOSTDOWN (117 + ESP_ERR_ERRNO_BASE)            /*!< Host is down */
#define ESP_ERR_EHOSTUNREACH (118 + ESP_ERR_ERRNO_BASE)         /*!< Host is unreachable */
#define ESP_ERR_EINPROGRESS (119 + ESP_ERR_ERRNO_BASE)          /*!< Connection already in progress */
#define ESP_ERR_EALREADY (120 + ESP_ERR_ERRNO_BASE)             /*!< Socket already connected */
#define ESP_ERR_EDESTADDRREQ (121 + ESP_ERR_ERRNO_BASE)         /*!< Destination address required */
#define ESP_ERR_EMSGSIZE (122 + ESP_ERR_ERRNO_BASE)             /*!< Message too long */
#define ESP_ERR_EPROTONOSUPPORT (123 + ESP_ERR_ERRNO_BASE)      /*!< Unknown protocol */
#define ESP_ERR_ESOCKTNOSUPPORT (124 + ESP_ERR_ERRNO_BASE)      /*!< Socket type not supported */
#define ESP_ERR_EADDRNOTAVAIL (125 + ESP_ERR_ERRNO_BASE)        /*!< Address not available */
#define ESP_ERR_ENETRESET (126 + ESP_ERR_ERRNO_BASE)            /*!< Connection aborted by network */
#define ESP_ERR_EISCONN (127 + ESP_ERR_ERRNO_BASE)              /*!< Socket is already connected */
#define ESP_ERR_ENOTCONN (128 + ESP_ERR_ERRNO_BASE)             /*!< Socket is not connected */
#define ESP_ERR_ETOOMANYREFS (129 + ESP_ERR_ERRNO_BASE)
#define ESP_ERR_EPROCLIM (130 + ESP_ERR_ERRNO_BASE)
#define ESP_ERR_EUSERS (131 + ESP_ERR_ERRNO_BASE)
#define ESP_ERR_EDQUOT (132 + ESP_ERR_ERRNO_BASE)
#define ESP_ERR_ESTALE (133 + ESP_ERR_ERRNO_BASE)
#define ESP_ERR_ENOTSUP (134 + ESP_ERR_ERRNO_BASE)              /*!< Not supported */
#define ESP_ERR_ENOMEDIUM (135  + ESP_ERR_ERRNO_BASE)           /*!< No medium (in tape drive) */
#define ESP_ERR_ENOSHARE (136  + ESP_ERR_ERRNO_BASE)            /*!< No such host or network path */
#define ESP_ERR_ECASECLASH (137 + ESP_ERR_ERRNO_BASE)           /*!< Filename exists with different case */
#define ESP_ERR_EILSEQ (138 + ESP_ERR_ERRNO_BASE)               /*!< Illegal byte sequence */
#define ESP_ERR_EOVERFLOW (139 + ESP_ERR_ERRNO_BASE)            /*!< Value too large for defined data type */
#define ESP_ERR_ECANCELED (140 + ESP_ERR_ERRNO_BASE)            /*!< Operation canceled */
#define ESP_ERR_ENOTRECOVERABLE (141 + ESP_ERR_ERRNO_BASE)      /*!< State not recoverable */
#define ESP_ERR_EOWNERDEAD (142 + ESP_ERR_ERRNO_BASE)           /*!< Previous owner died */
#define ESP_ERR_ESTRPIPE (143 + ESP_ERR_ERRNO_BASE)             /*!< Streams pipe error */
#define ESP_ERR_EWOULDBLOCK EAGAIN + ESP_ERR_ERRNO_BASE)        /*!< Operation would block */

Who is online

Users browsing this forum: No registered users and 151 guests