How about standard Error Codes?

How about having Arduino IDE ship with an include file with standard error codes that could be used by libraries and sketches:

#ifndef ERRORCODES_H
#define ERRORCODES_H

//! \version 1.2
enum ErrorCode {
    SUCCESS=        0,
    ERROR_CHECKSUM=         -9999,
    ERROR_TIMEOUT=          -9998,
    ERROR_DISABLED=         -9997,
    ERROR_UNSUPPORTED=      -9996,
    ERROR_UNKNOWN_RSP=      -9995,
    ERROR_BAD_COMMAND=      -9994,
    ERROR_DIRECTORY=        -9993,
    ERROR_FILENAME=         -9992,
    ERROR_NOT_ANALOG_PIN=   -9991,
    ERROR_NOT_DIGITAL_PIN=  -9990,
    ERROR_NOT_INTERRUPT_PIN= -9989,
    ERROR_NOT_PWM_PIN=      -9988,
    ERROR_NOT_SERIAL_PIN=   -9987,
    ERROR_READ=             -9986,
    ERROR_WRITE=            -9985,
    ERROR_BAD_PARAM=        -9984,
    ERROR_INIT1=            -9983,
    ERROR_INIT2=            -9982,
    ERROR_INIT3=            -9981,
    ERROR_NO_DATA=          -9980,
    ERROR_NO_MEMORY=        -9979,
};

#endif // ERRORCODES_H

I like the idea but I don't know if it would work in practice for all projects. I think every library could include such a list as it documents all errors in one place.

sort of best practice.

I like that you live by your motto. :slight_smile:

I think with feedback from the Arduino forum, you could have a consolidated error list that would cover 80% of the standard error conditions. It would make it a lot easier to figure out how to use a new library - and it might remind library writers to check for common error conditions.

I changed two of my libs on the playground with error codes in the .h file

improved the readability of the example and I could remove some comments explaining magic numbers :slight_smile:

log on to your favorite unix box and look at /usr/include/sys/errno.h . Then look up the perror() function.

Unix has been doing it this way for years. Works quite well. I'll be some form of errno.h and perror() would work out well for the arduino, too.

-j