Cannot get strerror to return a string

Working with the File Systems and looking at the examples it is setting errno, and while not terribly important, the examples show (in the logging section) using strerror to return a readable string of the error:

void setup() {
    Log.info("Connecting to server");
    int error = connect();
    if (error) {
        // Get error message string
        const char *message = strerror(error);
        // Log message with additional attributes
        Log.code(error).details(message).error("Connection error");
    }
}

For the file system specifically errno is equal to ENOENT, but strerror returns nothing. Am I missing something simple?

I believe the problem is that details are not displayed in log messages by default. This should work instead:

Log.error("Connection error %d %s", error, message);

However, the other issue is that while the file system sets errno, most other functions do not. For example, if you are using TCP or UDP in connect(), those won’t set errno. The reason is that the file system uses the POSIX API, which uses errno. TCP and UDP use the Arduino Wiring API, which does not.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.