From 4406961ce09b69888bf3a3e49ed8c691629b64a3 Mon Sep 17 00:00:00 2001 From: Jerry Johns Date: Thu, 15 Sep 2022 09:58:51 -0400 Subject: [PATCH] Remove KeyError encountered on unknown attributes (#22600) This removes the KeyError exception that is thrown when the Python cluster cache encounters an attribute that it doesn't have schema for. This occurs for some of the extended attributes in the test cluster that are not actually defined in schema. This ensures that we don't abruptly terminate attribute processing when running tests against the all clusters app. --- .../python/chip/clusters/Attribute.py | 27 ++++++++++--------- .../python/chip/clusters/attribute.cpp | 5 +--- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py index fc2ec8ec20ba7d..36d6e343f52b13 100644 --- a/src/controller/python/chip/clusters/Attribute.py +++ b/src/controller/python/chip/clusters/Attribute.py @@ -408,9 +408,14 @@ def UpdateCachedData(self): endpointCache = attributeCache[endpoint] for cluster in tlvCache[endpoint]: + if cluster not in _ClusterIndex: + # + # #22599 tracks dealing with unknown clusters more + # gracefully so that clients can still access this data. + # + continue + clusterType = _ClusterIndex[cluster] - if (clusterType is None): - raise Exception("Cannot find cluster in cluster index") if (clusterType not in endpointCache): endpointCache[clusterType] = {} @@ -427,9 +432,6 @@ def UpdateCachedData(self): endpointCache[clusterType].SetDataVersion( clusterDataVersion) except Exception as ex: - logging.error( - f"Error converting TLV to Cluster Object for path: Endpoint = {endpoint}, cluster = {str(clusterType)}") - logging.error(f"|-- Exception: {repr(ex)}") decodedValue = ValueDecodeFailure( tlvCache[endpoint][cluster], ex) endpointCache[clusterType] = decodedValue @@ -438,27 +440,26 @@ def UpdateCachedData(self): for attribute in tlvCache[endpoint][cluster]: value = tlvCache[endpoint][cluster][attribute] + if (cluster, attribute) not in _AttributeIndex: + # + # #22599 tracks dealing with unknown clusters more + # gracefully so that clients can still access this data. + # + continue + attributeType = _AttributeIndex[( cluster, attribute)][0] - if (attributeType is None): - raise Exception( - "Cannot find attribute in attribute index") if (attributeType not in clusterCache): clusterCache[attributeType] = {} if (type(value) is ValueDecodeFailure): - logging.error( - f"For path: Endpoint = {endpoint}, Attribute = {str(attributeType)}, got IM Error: {str(value.Reason)}") clusterCache[attributeType] = value else: try: decodedValue = attributeType.FromTagDictOrRawValue( tlvCache[endpoint][cluster][attribute]) except Exception as ex: - logging.error( - f"Error converting TLV to Cluster Object for path: Endpoint = {endpoint}, Attribute = {str(attributeType)}") - logging.error(f"|-- Exception: {repr(ex)}") decodedValue = ValueDecodeFailure(value, ex) clusterCache[attributeType] = decodedValue diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp index 488c1bc1c47521..0c90495ae4bf00 100644 --- a/src/controller/python/chip/clusters/attribute.cpp +++ b/src/controller/python/chip/clusters/attribute.cpp @@ -135,10 +135,7 @@ class ReadClientCallback : public ReadClient::Callback { version = aPath.mDataVersion.Value(); } - else - { - ChipLogError(DataManagement, "expect aPath has valid mDataVersion"); - } + gOnReadAttributeDataCallback(mAppContext, version, aPath.mEndpointId, aPath.mClusterId, aPath.mAttributeId, to_underlying(aStatus.mStatus), buffer.get(), size); }