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

Improve CHIP error constant defines to be consistent and accurate #1640

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/lib/core/CHIPError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
case CHIP_ERROR_UNKNOWN_TOPIC:
desc = "Unknown Topic";
break;

case CHIP_ERROR_TIMEOUT:
desc = "Timeout";
break;
Expand Down Expand Up @@ -283,7 +282,6 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
case CHIP_ERROR_UNSUPPORTED_AUTH_MODE:
desc = "Unsupported authentication mode";
break;

case CHIP_ERROR_INVALID_SERVICE_EP:
desc = "Invalid service endpoint";
break;
Expand All @@ -305,7 +303,6 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
case CHIP_ERROR_NO_SW_UPDATE_AVAILABLE:
desc = "No SW update available";
break;

case CHIP_ERROR_CA_CERT_NOT_FOUND:
desc = "CA certificate not found";
break;
Expand Down Expand Up @@ -342,7 +339,7 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
case CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION:
desc = "Unsupported CASE configuration";
break;
case CHIP_ERROR_CERT_LOAD_FAIL:
case CHIP_ERROR_CERT_LOAD_FAILED:
desc = "Unable to load certificate";
break;
case CHIP_ERROR_CERT_NOT_TRUSTED:
Expand Down Expand Up @@ -546,7 +543,7 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
case CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED:
desc = "Default event handler not called";
break;
case CHIP_ERROR_PERSISTED_STORAGE_FAIL:
case CHIP_ERROR_PERSISTED_STORAGE_FAILED:
desc = "Persisted storage failed";
break;
case CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND:
Expand Down Expand Up @@ -594,6 +591,18 @@ bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err)
case CHIP_ERROR_INTERNAL:
desc = "Internal error";
break;
case CHIP_ERROR_OPEN_FAILED:
desc = "Open file failed";
break;
case CHIP_ERROR_READ_FAILED:
desc = "Read from file failed";
break;
case CHIP_ERROR_WRITE_FAILED:
desc = "Write to file failed";
break;
case CHIP_ERROR_DECODE_FAILED:
desc = "Decoding failed";
break;
}
#endif // !CHIP_CONFIG_SHORT_ERROR_STR

Expand Down
48 changes: 40 additions & 8 deletions src/lib/core/CHIPError.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,13 +870,13 @@ typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR;
#define CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION _CHIP_ERROR(85)

/**
* @def CHIP_ERROR_CERT_LOAD_FAIL
* @def CHIP_ERROR_CERT_LOAD_FAILED
*
* @brief
* A certificate load failed.
*
*/
#define CHIP_ERROR_CERT_LOAD_FAIL _CHIP_ERROR(86)
#define CHIP_ERROR_CERT_LOAD_FAILED _CHIP_ERROR(86)

/**
* @def CHIP_ERROR_CERT_NOT_TRUSTED
Expand Down Expand Up @@ -1531,15 +1531,15 @@ typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR;
* the required elements, or it contais both the MergeData element
* and DeletedDictionaryKeyList.
*/
#define CHIP_ERROR_MALFORMED_DATA_ELEMENT _CHIP_ERROR(158)
#define CHIP_ERROR_MALFORMED_DATA_ELEMENT _CHIP_ERROR(158)

/**
* @def CHIP_ERROR_WRONG_CERT_TYPE
*
* @brief
* The presented certificate was of the wrong type.
*/
#define CHIP_ERROR_WRONG_CERT_TYPE _CHIP_ERROR(159)
#define CHIP_ERROR_WRONG_CERT_TYPE _CHIP_ERROR(159)

/**
* @def CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED
Expand All @@ -1551,13 +1551,13 @@ typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR;
#define CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED _CHIP_ERROR(162)

/**
* @def CHIP_ERROR_PERSISTED_STORAGE_FAIL
* @def CHIP_ERROR_PERSISTED_STORAGE_FAILED
*
* @brief
* Persisted storage memory read/write failure.
*
*/
#define CHIP_ERROR_PERSISTED_STORAGE_FAIL _CHIP_ERROR(163)
#define CHIP_ERROR_PERSISTED_STORAGE_FAILED _CHIP_ERROR(163)

/**
* @def CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND
Expand Down Expand Up @@ -1668,7 +1668,7 @@ typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR;
* same Trait Instance.
*
*/
#define CHIP_ERROR_INCONSISTENT_CONDITIONALITY _CHIP_ERROR(179)
#define CHIP_ERROR_INCONSISTENT_CONDITIONALITY _CHIP_ERROR(179)

/**
* @def CHIP_ERROR_LOCAL_DATA_INCONSISTENT
Expand All @@ -1678,7 +1678,7 @@ typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR;
* Trait Instance and cannot support the operation requested.
*
*/
#define CHIP_ERROR_LOCAL_DATA_INCONSISTENT _CHIP_ERROR(180)
#define CHIP_ERROR_LOCAL_DATA_INCONSISTENT _CHIP_ERROR(180)

/**
* @def CHIP_EVENT_ID_FOUND
Expand All @@ -1696,6 +1696,38 @@ typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR;
*/
#define CHIP_ERROR_INTERNAL _CHIP_ERROR(183)

/**
* @def CHIP_ERROR_OPEN_FAILED
*
* @brief
* Open file failed
*/
#define CHIP_ERROR_OPEN_FAILED _CHIP_ERROR(184)

/**
* @def CHIP_ERROR_READ_FAILED
*
* @brief
* Read from file failed
*/
#define CHIP_ERROR_READ_FAILED _CHIP_ERROR(185)

/**
* @def CHIP_ERROR_WRITE_FAILED
*
* @brief
* Write to file failed
*/
#define CHIP_ERROR_WRITE_FAILED _CHIP_ERROR(186)

/**
* @def CHIP_ERROR_DECODE_FAILED
*
* @brief
* Decoding failed
*/
#define CHIP_ERROR_DECODE_FAILED _CHIP_ERROR(187)

/**
* @}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/lib/core/tests/TestCHIPErrorStr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static int32_t sContext[] =
CHIP_ERROR_CERT_NOT_FOUND,
CHIP_ERROR_INVALID_CASE_PARAMETER,
CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION,
CHIP_ERROR_CERT_LOAD_FAIL,
CHIP_ERROR_CERT_LOAD_FAILED,
CHIP_ERROR_CERT_NOT_TRUSTED,
CHIP_ERROR_INVALID_ACCESS_TOKEN,
CHIP_ERROR_WRONG_CERT_SUBJECT,
Expand Down Expand Up @@ -211,7 +211,7 @@ static int32_t sContext[] =
CHIP_ERROR_MALFORMED_DATA_ELEMENT,
CHIP_ERROR_WRONG_CERT_TYPE,
CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED,
CHIP_ERROR_PERSISTED_STORAGE_FAIL,
CHIP_ERROR_PERSISTED_STORAGE_FAILED,
CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND,
CHIP_ERROR_PROFILE_STRING_CONTEXT_ALREADY_REGISTERED,
CHIP_ERROR_PROFILE_STRING_CONTEXT_NOT_REGISTERED,
Expand Down
14 changes: 7 additions & 7 deletions src/lib/support/tests/TestPersistedStorageImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ static CHIP_ERROR GetCounterValueFromFile(const char * aKey, uint32_t & aValue)
{
if (fgets(value, sizeof(value), sPersistentStoreFile) == NULL)
{
err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}
else
{
RemoveEndOfLineSymbol(value);

if (!ParseInt(value, aValue, 0))
err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
}

ExitNow();
Expand Down Expand Up @@ -115,7 +115,7 @@ static CHIP_ERROR SaveCounterValueToFile(const char * aKey, uint32_t aValue)
if (strcmp(key, aKey) == 0)
{
res = fputs(value, sPersistentStoreFile);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAIL);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

ExitNow();
}
Expand All @@ -124,13 +124,13 @@ static CHIP_ERROR SaveCounterValueToFile(const char * aKey, uint32_t aValue)
// If value not found in the file then write the counter key and
// the counter value to the end of the file.
res = fputs(aKey, sPersistentStoreFile);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAIL);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

res = fputs("\n", sPersistentStoreFile);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAIL);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

res = fputs(value, sPersistentStoreFile);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAIL);
VerifyOrExit(res != EOF, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

exit:
fflush(sPersistentStoreFile);
Expand All @@ -155,7 +155,7 @@ CHIP_ERROR Read(const char * aKey, uint32_t & aValue)
VerifyOrExit(it != sPersistentStore.end(), err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);

size_t aValueLength = Base64Decode(it->second.c_str(), strlen(it->second.c_str()), (uint8_t *) &aValue);
VerifyOrExit(aValueLength == sizeof(uint32_t), err = CHIP_ERROR_PERSISTED_STORAGE_FAIL);
VerifyOrExit(aValueLength == sizeof(uint32_t), err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);
}

exit:
Expand Down
30 changes: 15 additions & 15 deletions src/platform/Darwin/PosixConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CHIP_ERROR PosixConfig::Init()

CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -87,7 +87,7 @@ CHIP_ERROR PosixConfig::ReadConfigValue(Key key, bool & val)

CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint32_t & val)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -96,7 +96,7 @@ CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint32_t & val)

CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint64_t & val)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -105,7 +105,7 @@ CHIP_ERROR PosixConfig::ReadConfigValue(Key key, uint64_t & val)

CHIP_ERROR PosixConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize, size_t & outLen)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -114,7 +114,7 @@ CHIP_ERROR PosixConfig::ReadConfigValueStr(Key key, char * buf, size_t bufSize,

CHIP_ERROR PosixConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSize, size_t & outLen)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -123,7 +123,7 @@ CHIP_ERROR PosixConfig::ReadConfigValueBin(Key key, uint8_t * buf, size_t bufSiz

CHIP_ERROR PosixConfig::WriteConfigValue(Key key, bool val)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -132,7 +132,7 @@ CHIP_ERROR PosixConfig::WriteConfigValue(Key key, bool val)

CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint32_t val)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -141,7 +141,7 @@ CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint32_t val)

CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint64_t val)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -150,7 +150,7 @@ CHIP_ERROR PosixConfig::WriteConfigValue(Key key, uint64_t val)

CHIP_ERROR PosixConfig::WriteConfigValueStr(Key key, const char * str)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -159,7 +159,7 @@ CHIP_ERROR PosixConfig::WriteConfigValueStr(Key key, const char * str)

CHIP_ERROR PosixConfig::WriteConfigValueStr(Key key, const char * str, size_t strLen)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -168,7 +168,7 @@ CHIP_ERROR PosixConfig::WriteConfigValueStr(Key key, const char * str, size_t st

CHIP_ERROR PosixConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_t dataLen)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -177,7 +177,7 @@ CHIP_ERROR PosixConfig::WriteConfigValueBin(Key key, const uint8_t * data, size_

CHIP_ERROR PosixConfig::ClearConfigValue(Key key)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -191,7 +191,7 @@ bool PosixConfig::ConfigValueExists(Key key)

CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -200,7 +200,7 @@ CHIP_ERROR PosixConfig::EnsureNamespace(const char * ns)

CHIP_ERROR PosixConfig::ClearNamespace(const char * ns)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand All @@ -209,7 +209,7 @@ CHIP_ERROR PosixConfig::ClearNamespace(const char * ns)

CHIP_ERROR PosixConfig::FactoryResetConfig(void)
{
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_FAILED;
SuccessOrExit(err);

exit:
Expand Down
4 changes: 2 additions & 2 deletions src/platform/Linux/CHIPLinuxStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ CHIP_ERROR ChipLinuxStorage::ClearAll(void)
}
else
{
retval = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
retval = CHIP_ERROR_WRITE_FAILED;
}

return retval;
Expand Down Expand Up @@ -314,7 +314,7 @@ CHIP_ERROR ChipLinuxStorage::Commit(void)
}
else
{
retval = CHIP_ERROR_PERSISTED_STORAGE_FAIL;
retval = CHIP_ERROR_WRITE_FAILED;
}

return retval;
Expand Down
Loading