canonical / matter-pi-gpio-commander

Matter Raspberry Pi GPIO Commander - Turn your Pi into a Matter lighting device!
Apache License 2.0
90 stars 3 forks source link

Add error handling and implement number conversion for GPIO #12

Closed MonicaisHer closed 11 months ago

MonicaisHer commented 1 year ago

This PR adds a new function convertStringToIntNoExcept(), which utilizes std::strtol() to check whether the input environment variable GPIO is valid or not. This function is designed not to throw any exception errors, as exception throwing has been disabled by default in the SDK.

resolves #11

Test instruction

Build snap from this PR:

snapcraft 

Validate that the app will raise corresponding errors when the env var GPIO is either non-interger or invalid (less than 0):

sudo snap install ./matter-pi-gpio-commander_0.3.0_amd64.snap --devmode
  1. Invalid value (less or equal than 0):
    sudo snap set matter-pi-gpio-commander gpio=-1
    sudo snap start matter-pi-gpio-commander

    check logs for error message:

    CHIP:SVR: Invalid value for GPIO: -1
  2. Non-interger value:
    sudo snap set matter-pi-gpio-commander gpio="test-string"
    sudo snap start matter-pi-gpio-commander

    check logs for error message:

    CHIP:SVR: Non-integer value for GPIO: test-string