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

Outer try catch block in Parser updateVpdKeyword API #539

Open
wants to merge 1 commit into
base: 1110
Choose a base branch
from

Conversation

souvik1914581
Copy link

This commit adds an outer try catch block in Parser::updateVpdKeyword API. Currently, this API has multiple return statements for different error scenarios, which reduces the API body's readability and modularity.
In order to streamline and handle all errors in a single location, an outer try catch has been added in the API body.

Test:

'''
Trigger this API by calling WriteKeyword API from D-Bus:

root@testhostname2:~# busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv "/sys/bus/i2c/drivers/at24/8-0050/eeprom" (ss) "UTIL" "D0" v ay 1 1

root@testhostname2:~# busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager WriteKeyword sv "/sys/bus/i2c/drivers/at24/8-0050/eeprom" (ssay) "UTIL" "D0" 1 0 i 1

root@testhostname2:~# busctl call com.ibm.VPD.Manager /com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv "/sys/bus/i2c/drivers/at24/8-0050/eeprom" (ss) "UTIL" "D0" v ay 1 0
'''

Change-Id: I66a6c95ca0daaebb0a6f5c80e28ad4e9706d776f

souvik1914581 pushed a commit to souvik1914581/openpower-vpd-parser that referenced this pull request Dec 12, 2024
This commit adds an outer try catch block in Parser::updateVpdKeyword
API. Currently, this API has multiple return statements for different
error scenarios, which reduces the API body's readability and
modularity.
In order to streamline and handle all errors in a single location, an
outer try catch has been added in the API body.

Test:

'''
Trigger this API by calling WriteKeyword API from D-Bus:

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 1

root@testhostname2:~#  busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager WriteKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ssay\) "UTIL" "D0" 1 0
i 1

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 0
'''

Change-Id: I66a6c95ca0daaebb0a6f5c80e28ad4e9706d776f
Signed-off-by: Souvik Roy <[email protected]>
@souvik1914581 souvik1914581 force-pushed the sr_addOuterTryCatchInUpdateVpdKeyword branch from 3d5407d to 8d22a83 Compare December 12, 2024 14:16
souvik1914581 pushed a commit to souvik1914581/openpower-vpd-parser that referenced this pull request Dec 12, 2024
This commit adds an outer try catch block in Parser::updateVpdKeyword
API. Currently, this API has multiple return statements for different
error scenarios, which reduces the API body's readability and
modularity.
In order to streamline and handle all errors in a single location, an
outer try catch has been added in the API body.

This commit also adds constants to define success and failure for APIs
which return 0 or -1.

Test:

'''
Trigger this API by calling WriteKeyword API from D-Bus:

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 1

root@testhostname2:~#  busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager WriteKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ssay\) "UTIL" "D0" 1 0
i 1

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 0
'''

Change-Id: I66a6c95ca0daaebb0a6f5c80e28ad4e9706d776f
Signed-off-by: Souvik Roy <[email protected]>
@souvik1914581 souvik1914581 force-pushed the sr_addOuterTryCatchInUpdateVpdKeyword branch from 8d22a83 to bf8679c Compare December 12, 2024 14:29
@branupama
Copy link

which reduces the API body's readability and modularity.

this is not the case.

vpd-manager/src/parser.cpp Show resolved Hide resolved

// TODO: Check if revert is required when any of the writes fails.
// TODO: Handle error logging
return constants::FAILURE;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we dont need this statement, as we will return at the end anyways. ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose line 69 writeKeywordOnHardware is successful, l_bytesUpdatedOnHardware has some value > 0, but any subsequent steps like updateVpdKeywordOnRedundantPath fails, we have to return -1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

if (updateVpdKeywordOnRedundantPath(l_redundantFruPath,
i_paramsToWriteData) < 0)
std::string l_keywordIdentifier{};
if (const types::IpzData* l_ipzData =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as all the throw has sufficient information,
do we need extra log here, printing l_ex.what() is enough ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The throws do not log the Record Name and Keyword Name.

souvik1914581 pushed a commit to souvik1914581/openpower-vpd-parser that referenced this pull request Dec 13, 2024
This commit adds an outer try catch block in Parser::updateVpdKeyword
API. Currently, this API has multiple return statements for different
error scenarios, which reduces the API body's readability and
modularity.
In order to streamline and handle all errors in a single location, an
outer try catch has been added in the API body.

This commit also adds constants to define success and failure for APIs
which return 0 or -1.

Test:

'''
Trigger this API by calling WriteKeyword API from D-Bus:

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 1

root@testhostname2:~#  busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager WriteKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ssay\) "UTIL" "D0" 1 0
i 1

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 0
'''

Change-Id: I66a6c95ca0daaebb0a6f5c80e28ad4e9706d776f
Signed-off-by: Souvik Roy <[email protected]>
@souvik1914581 souvik1914581 force-pushed the sr_addOuterTryCatchInUpdateVpdKeyword branch from bf8679c to 74b9822 Compare December 13, 2024 04:36
This commit adds an outer try catch block in Parser::updateVpdKeyword
API. Currently, this API has multiple return statements for different
error scenarios, which reduces the API body's readability and
modularity.
In order to streamline and handle all errors in a single location, an
outer try catch has been added in the API body.

This commit also adds constants to define success and failure for APIs
which return 0 or -1.

Test:

'''
Trigger this API by calling WriteKeyword API from D-Bus:

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 1

root@testhostname2:~#  busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager WriteKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ssay\) "UTIL" "D0" 1 0
i 1

root@testhostname2:~# busctl call com.ibm.VPD.Manager
/com/ibm/VPD/Manager com.ibm.VPD.Manager ReadKeyword sv
"/sys/bus/i2c/drivers/at24/8-0050/eeprom" \(ss\) "UTIL" "D0"
v ay 1 0
'''

Change-Id: I66a6c95ca0daaebb0a6f5c80e28ad4e9706d776f
Signed-off-by: Souvik Roy <[email protected]>
@souvik1914581 souvik1914581 force-pushed the sr_addOuterTryCatchInUpdateVpdKeyword branch from 74b9822 to 8e0beac Compare December 13, 2024 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants