Skip to content

Commit

Permalink
Map the return error from AppendUserLabel to RESOURCE_EXHAUSTED (proj…
Browse files Browse the repository at this point in the history
…ect-chip#36868)

* Map the return error from AppendUserLabel to RESOURCE_EXHAUSTED

* Restyled by whitespace

* Addressed the review comments

* Update API comment to algin with implemantion

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
yufengwangca and restyled-commits authored Dec 18, 2024
1 parent 37fa873 commit 3314bc3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/app/clusters/user-label-server/user-label-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,14 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath &
ReturnErrorOnFailure(aDecoder.Decode(entry));
VerifyOrReturnError(IsValidLabelEntry(entry), CHIP_IM_GLOBAL_STATUS(ConstraintError));

return provider->AppendUserLabel(endpoint, entry);
// Append the single user label entry
CHIP_ERROR err = provider->AppendUserLabel(endpoint, entry);
if (err == CHIP_ERROR_NO_MEMORY)
{
return CHIP_IM_GLOBAL_STATUS(ResourceExhausted);
}

return err;
}

return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
Expand Down
4 changes: 2 additions & 2 deletions src/app/tests/suites/TestUserLabelClusterConstraints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ tests:
]
response:
# When the cluster runs out of capacity to store these entries,
# we expect a FAILURE get returned.
error: FAILURE
# we expect a RESOURCE_EXHAUSTED get returned.
error: RESOURCE_EXHAUSTED
38 changes: 38 additions & 0 deletions src/include/platform/DeviceInfoProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,46 @@ class DeviceInfoProvider
*/
void SetStorageDelegate(PersistentStorageDelegate * storage);

/**
* @brief Sets the user label list for a specified endpoint.
*
* Replaces the current user label list with a new list. If the new list is smaller
* than the existing one, excess labels are deleted to free up space.
*
* @param[in] endpoint The endpoint ID associated with the user label list.
* @param[in] labelList The new list of user labels to store.
*
* @return CHIP_NO_ERROR on success.
* @return CHIP_ERROR if an error occurs.
*/
CHIP_ERROR SetUserLabelList(EndpointId endpoint, const AttributeList<UserLabelType, kMaxUserLabelListLength> & labelList);

/**
* @brief Clears the user label list for a specified endpoint.
*
* Deletes all user labels associated with the given endpoint, resetting the list length to zero.
* If no previous list exists, this function has no effect.
*
* @param[in] endpoint The endpoint ID whose user label list will be cleared.
*
* @return CHIP_NO_ERROR on success or if no previous value exists.
* @return CHIP_ERROR if an error occurs during deletion.
*/
CHIP_ERROR ClearUserLabelList(EndpointId endpoint);

/**
* @brief Appends a user label to the user label list for a specified endpoint.
*
* Adds a new label to the end of the existing user label list. The list size must not
* exceed `kMaxUserLabelListLength`. If the list is full, the function returns an error.
*
* @param[in] endpoint The endpoint ID to which the user label will be added.
* @param[in] label The user label to append to the list.
*
* @return CHIP_NO_ERROR on success.
* @return CHIP_ERROR_NO_MEMORY if the list is already at its maximum size.
* @return CHIP_ERROR if an error occurs during storage.
*/
CHIP_ERROR AppendUserLabel(EndpointId endpoint, const UserLabelType & label);

// Iterators
Expand Down

0 comments on commit 3314bc3

Please sign in to comment.