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 CHIP-compliant error handling to the app #9

Closed MonicaisHer closed 1 year ago

MonicaisHer commented 1 year ago

This PR adds a CHIP-compliant error handling that triggers a fatal error and gracefully shuts down the app when the environment variable GPIO is either unset or set to null.

Test instruction

Build snap from this PR:

snapcraft 

Validate that the app will raise an error and exit gracefully when the env var GPIO is either unset or set to null:

sudo snap install ./matter-pi-gpio-commander_0.3.0_amd64.snap --devmode
sudo snap connect matter-pi-gpio-commander:avahi-control
sudo snap set matter-pi-gpio-commander gpio=
sudo snap start matter-pi-gpio-commander
$ sudo journalctl -f | grep matter-pi-gpio-commander
...
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898229][1899642:1899642] CHIP:SVR: Environment variable not set or empty: GPIO
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898251][1899642:1899642] CHIP:DL: writing settings to file (/mnt/chip_counters.ini-VW2sPo)
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898298][1899642:1899642] CHIP:DL: renamed tmp file to file (/mnt/chip_counters.ini)
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898305][1899642:1899642] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898306][1899642:1899642] CHIP:DL: Inet Layer shutdown
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898308][1899642:1899642] CHIP:DL: BLE shutdown
Feb 28 13:55:03 ubuntu matter-pi-gpio-commander.lighting[1899642]: [1677588903.898309][1899642:1899642] CHIP:DL: System Layer shutdown
Feb 28 13:55:03 ubuntu systemd[1]: snap.matter-pi-gpio-commander.lighting.service: Main process exited, code=exited, status=255/EXCEPTION
Feb 28 13:55:03 ubuntu systemd[1]: snap.matter-pi-gpio-commander.lighting.service: Failed with result 'exit-code'.