Skip to content

Potential crash on I2C communication failure due to ESP_ERROR_CHECK #786

Description

@devprofile98

Hi, Thanks for the great library.

I am using i2cdev and esp-idf for an ESP32 project to connect to MPU6050, everything is ok in debug build, but in production, I think the ESP_ERROR_CHECK is misused, for example, the i2c_master_cmd_begin function can fail because the bus is busy (ESP_ERR_TIMEOUT), In debug environments this result in calling aborrt(), which could be ok in many cases, but in production the ESP_ERROR_CHECK macro became empty, and the writeBytes function will return true. This behavior is not suitable for a robust production application, considering I2C is a sensitive protocol.

Isn't it better to leverage a more appropriate error handling using if/else statements or just by returning the esp_err_t from the called function? What do you think?

Activity

  1. jrowberg commented on Aug 11, 2025

    @jrowberg
    Owner

    This is a good observation, but I feel like I don't have much to offer directly because I've never used the ESP IDF development approach--only the Arduino platform implementation. Someone else contributed the IDF variant of the I2Cdevlib core. Could you fork, modify, and submit a tested pull request that improves things to add the functionality you recommend?

  2. devprofile98 commented on Aug 12, 2025

    @devprofile98
    Author

    Of course, I will try to give the function correct return types and replace ESP_ERROR_CHECKs with robust error handling. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions