Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[examples] Add error handling of LightingMgr().Init() #25398

Merged

Conversation

MonicaisHer
Copy link
Contributor

@MonicaisHer MonicaisHer commented Mar 1, 2023

Problem

In the lighting app Linux example, LightingMgr().Init() returned a chip error which was not handled by the application.

Changes

To address this issue, this PR improves the error handling of LightingMgr().Init(). The lighting application will trigger a fatal error and shut down gracefully in the event of an error.

Testing

To verify the effectiveness of the changes made, I intentionally induced an error by changing the CHIP_NO_ERROR to CHIP_ERROR_INVALID_ARGUMENT in the following LightingManager.cpp file:


So, the code block above will look like this:

CHIP_ERROR LightingManager::Init()
{
    mState = kState_On;
    return CHIP_ERROR_INVALID_ARGUMENT;
}

Validate that the application will capture and print out the error, then exit gracefully by checking the logs:

$ sudo ./out/build/chip-lighting-app 
[1677690023.397204][2408322:2408322] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_kvs
[1677690023.397349][2408322:2408322] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_kvs
[1677690023.397355][2408322:2408322] CHIP:DL: ChipLinuxStorage::Init: Attempt to re-initialize with KVS config file: /tmp/chip_kvs
[1677690023.397406][2408322:2408322] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_factory.ini
[1677690023.397429][2408322:2408322] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_config.ini
[1677690023.397439][2408322:2408322] CHIP:DL: ChipLinuxStorage::Init: Using KVS config file: /tmp/chip_counters.ini
[1677690023.397503][2408322:2408322] CHIP:DL: writing settings to file (/tmp/chip_counters.ini-3QDCzb)
[1677690023.397608][2408322:2408322] CHIP:DL: renamed tmp file to file (/tmp/chip_counters.ini)
[1677690023.397619][2408322:2408322] CHIP:DL: NVS set: chip-counters/reboot-count = 45 (0x2D)
[1677690023.397845][2408322:2408322] CHIP:DL: Got Ethernet interface: eno1
[1677690023.398037][2408322:2408322] CHIP:DL: Found the primary Ethernet interface:eno1
[1677690023.398216][2408322:2408322] CHIP:DL: Failed to get WiFi interface
[1677690023.398220][2408322:2408322] CHIP:DL: Failed to reset WiFi statistic counts
[1677690023.398226][2408322:2408322] CHIP:SPT: *** WARNING: Using temporary passcode 20202021 due to no neither --passcode or --spake2p-verifier-base64 given on command line. This is temporary and will disappear. Please update your scripts to explicitly configure onboarding credentials. ***
[1677690023.398229][2408322:2408322] CHIP:SPT: *** WARNING: Using temporary test discriminator 3840 due to --discriminator not given on command line. This is temporary and will disappear. Please update your scripts to explicitly configure discriminator. ***
[1677690023.398232][2408322:2408322] CHIP:SPT: PASE PBKDF iterations set to 1000
[1677690023.398236][2408322:2408322] CHIP:SPT: LinuxCommissionableDataProvider didn't get a PASE salt, generating one.
[1677690023.399054][2408322:2408322] CHIP:DL: Device Configuration:
[1677690023.399060][2408322:2408322] CHIP:DL:   Serial Number: TEST_SN
[1677690023.399065][2408322:2408322] CHIP:DL:   Vendor Id: 65521 (0xFFF1)
[1677690023.399071][2408322:2408322] CHIP:DL:   Product Id: 32769 (0x8001)
[1677690023.399073][2408322:2408322] CHIP:DL:   Product Name: TEST_PRODUCT
[1677690023.399077][2408322:2408322] CHIP:DL:   Hardware Version: 0
[1677690023.399079][2408322:2408322] CHIP:DL:   Setup Pin Code (0 for UNKNOWN/ERROR): 20202021
[1677690023.399080][2408322:2408322] CHIP:DL:   Setup Discriminator (0xFFFF for UNKNOWN/ERROR): 3840 (0xF00)
[1677690023.399084][2408322:2408322] CHIP:DL:   Manufacturing Date: (not set)
[1677690023.399087][2408322:2408322] CHIP:DL:   Device Type: 257 (0x101)
[1677690023.399090][2408322:2408322] CHIP:-: ==== Onboarding payload for Standard Commissioning Flow ====
[1677690023.399095][2408322:2408322] CHIP:SVR: SetupQRCode: [MT:-24J042C00KA0648G00]
[1677690023.399099][2408322:2408322] CHIP:SVR: Copy/paste the below URL in a browser to see the QR Code:
[1677690023.399100][2408322:2408322] CHIP:SVR: https://project-chip.github.io/connectedhomeip/qrcode.html?data=MT%3A-24J042C00KA0648G00
[1677690023.399104][2408322:2408322] CHIP:SVR: Manual pairing code: [34970112332]
[1677690023.399111][2408322:2408322] CHIP:SVR: Failed to initialize lighting manager: ../../third_party/connectedhomeip/examples/lighting-app/lighting-common/src/LightingManager.cpp:29: CHIP Error 0x0000002F: Invalid argument
[1677690023.399141][2408322:2408322] CHIP:DL: writing settings to file (/tmp/chip_counters.ini-3ZHjQa)
[1677690023.399211][2408322:2408322] CHIP:DL: renamed tmp file to file (/tmp/chip_counters.ini)
[1677690023.399219][2408322:2408322] CHIP:DL: NVS set: chip-counters/total-operational-hours = 0 (0x0)
[1677690023.399222][2408322:2408322] CHIP:DL: Inet Layer shutdown
[1677690023.399225][2408322:2408322] CHIP:DL: BLE shutdown
[1677690023.399227][2408322:2408322] CHIP:DL: System Layer shutdown
$ echo $?
255

@CLAassistant
Copy link

CLAassistant commented Mar 1, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

github-actions bot commented Mar 6, 2023

PR #25398: Size comparison from 32fb896 to 6da7636

Full report (2 builds for cc32xx, mbed)
platform target config section 32fb896 6da7636 change % change
cc32xx lock CC3235SF_LAUNCHXL 0 0 0 0.0
(read only) 643465 643465 0 0.0
(read/write) 203688 203688 0 0.0
.ARM.attributes 44 44 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 197088 197088 0 0.0
.comment 194 194 0 0.0
.data 1480 1480 0 0.0
.debug_abbrev 930213 930213 0 0.0
.debug_aranges 87336 87336 0 0.0
.debug_frame 300024 300024 0 0.0
.debug_info 20262927 20262927 0 0.0
.debug_line 2657822 2657822 0 0.0
.debug_loc 2800026 2800026 0 0.0
.debug_ranges 282240 282240 0 0.0
.debug_str 3023883 3023883 0 0.0
.ramVecs 780 780 0 0.0
.resetVecs 64 64 0 0.0
.rodata 105929 105929 0 0.0
.shstrtab 232 232 0 0.0
.stab 204 204 0 0.0
.stabstr 441 441 0 0.0
.stack 2048 2048 0 0.0
.strtab 378514 378514 0 0.0
.symtab 256560 256560 0 0.0
.text 535412 535412 0 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2467384 2467384 0 0.0
.bss 215804 215804 0 0.0
.data 5880 5880 0 0.0
.text 1430028 1430028 0 0.0

@MonicaisHer
Copy link
Contributor Author

@andy31415 @bzbarsky-apple Could we merge this? Thank you.

@bzbarsky-apple
Copy link
Contributor

@MonicaisHer I don't have permissions to merge this because the pullapprove job is failing... You need @andy31415 or @woody-apple

@andy31415 andy31415 merged commit 9829096 into project-chip:master Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants