Skip to content

Commit 3314bc3

Browse files
Map the return error from AppendUserLabel to RESOURCE_EXHAUSTED (#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 <commits@restyled.io>
1 parent 37fa873 commit 3314bc3

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/app/clusters/user-label-server/user-label-server.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ CHIP_ERROR UserLabelAttrAccess::WriteLabelList(const ConcreteDataAttributePath &
151151
ReturnErrorOnFailure(aDecoder.Decode(entry));
152152
VerifyOrReturnError(IsValidLabelEntry(entry), CHIP_IM_GLOBAL_STATUS(ConstraintError));
153153

154-
return provider->AppendUserLabel(endpoint, entry);
154+
// Append the single user label entry
155+
CHIP_ERROR err = provider->AppendUserLabel(endpoint, entry);
156+
if (err == CHIP_ERROR_NO_MEMORY)
157+
{
158+
return CHIP_IM_GLOBAL_STATUS(ResourceExhausted);
159+
}
160+
161+
return err;
155162
}
156163

157164
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;

src/app/tests/suites/TestUserLabelClusterConstraints.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ tests:
8585
]
8686
response:
8787
# When the cluster runs out of capacity to store these entries,
88-
# we expect a FAILURE get returned.
89-
error: FAILURE
88+
# we expect a RESOURCE_EXHAUSTED get returned.
89+
error: RESOURCE_EXHAUSTED

src/include/platform/DeviceInfoProvider.h

+38
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,46 @@ class DeviceInfoProvider
8989
*/
9090
void SetStorageDelegate(PersistentStorageDelegate * storage);
9191

92+
/**
93+
* @brief Sets the user label list for a specified endpoint.
94+
*
95+
* Replaces the current user label list with a new list. If the new list is smaller
96+
* than the existing one, excess labels are deleted to free up space.
97+
*
98+
* @param[in] endpoint The endpoint ID associated with the user label list.
99+
* @param[in] labelList The new list of user labels to store.
100+
*
101+
* @return CHIP_NO_ERROR on success.
102+
* @return CHIP_ERROR if an error occurs.
103+
*/
92104
CHIP_ERROR SetUserLabelList(EndpointId endpoint, const AttributeList<UserLabelType, kMaxUserLabelListLength> & labelList);
105+
106+
/**
107+
* @brief Clears the user label list for a specified endpoint.
108+
*
109+
* Deletes all user labels associated with the given endpoint, resetting the list length to zero.
110+
* If no previous list exists, this function has no effect.
111+
*
112+
* @param[in] endpoint The endpoint ID whose user label list will be cleared.
113+
*
114+
* @return CHIP_NO_ERROR on success or if no previous value exists.
115+
* @return CHIP_ERROR if an error occurs during deletion.
116+
*/
93117
CHIP_ERROR ClearUserLabelList(EndpointId endpoint);
118+
119+
/**
120+
* @brief Appends a user label to the user label list for a specified endpoint.
121+
*
122+
* Adds a new label to the end of the existing user label list. The list size must not
123+
* exceed `kMaxUserLabelListLength`. If the list is full, the function returns an error.
124+
*
125+
* @param[in] endpoint The endpoint ID to which the user label will be added.
126+
* @param[in] label The user label to append to the list.
127+
*
128+
* @return CHIP_NO_ERROR on success.
129+
* @return CHIP_ERROR_NO_MEMORY if the list is already at its maximum size.
130+
* @return CHIP_ERROR if an error occurs during storage.
131+
*/
94132
CHIP_ERROR AppendUserLabel(EndpointId endpoint, const UserLabelType & label);
95133

96134
// Iterators

0 commit comments

Comments
 (0)