Skip to content

Commit bbf4320

Browse files
authored
Adding log warnings in helpers when data types cannot be determined (#1654)
Github: ZAP#1247
1 parent a4e678c commit bbf4320

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

src-electron/db/query-data-type.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ async function selectSizeFromType(db, packageIds, value) {
240240
) {
241241
return null
242242
} else {
243+
envConfig.logError(
244+
`In selectSizeFromType, could not determine the data type. Original value: ${JSON.stringify(value)}, resolved dataType: ${JSON.stringify(dataType)}`
245+
)
243246
return null
244247
}
245248
} catch (err) {

src-electron/generator/helper-attribute.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
const queryAttribute = require('../db/query-attribute')
2525
const queryZcl = require('../db/query-zcl')
2626
const templateUtil = require('./template-util')
27-
const zclUtil = require('../util/zcl-util')
27+
const envConfig = require('../util/env')
2828
const dbEnum = require('../../src-shared/db-enum')
2929

3030
/**
@@ -144,7 +144,10 @@ async function as_underlying_atomic_identifier_for_attribute_id(attributeId) {
144144
attributeDetails.clusterRef,
145145
[attributeDetails.packageRef]
146146
)
147-
if (dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum) {
147+
if (
148+
dataType &&
149+
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum
150+
) {
148151
let enumInfo = await queryZcl.selectEnumByNameAndClusterId(
149152
this.global.db,
150153
attributeDetails.type,
@@ -158,6 +161,7 @@ async function as_underlying_atomic_identifier_for_attribute_id(attributeId) {
158161
)
159162
return atomicInfo ? atomicInfo.atomicId : null
160163
} else if (
164+
dataType &&
161165
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap
162166
) {
163167
let bitmapInfo = await queryZcl.selectBitmapByNameAndClusterId(
@@ -173,6 +177,7 @@ async function as_underlying_atomic_identifier_for_attribute_id(attributeId) {
173177
)
174178
return atomicInfo ? atomicInfo.atomicId : null
175179
} else if (
180+
dataType &&
176181
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.struct
177182
) {
178183
atomicInfo = await queryZcl.selectAtomicType(
@@ -182,6 +187,7 @@ async function as_underlying_atomic_identifier_for_attribute_id(attributeId) {
182187
)
183188
return atomicInfo ? atomicInfo.atomicId : null
184189
} else if (
190+
dataType &&
185191
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.array
186192
) {
187193
atomicInfo = await queryZcl.selectAtomicType(
@@ -191,6 +197,9 @@ async function as_underlying_atomic_identifier_for_attribute_id(attributeId) {
191197
)
192198
return atomicInfo ? atomicInfo.atomicId : null
193199
} else {
200+
envConfig.logError(
201+
`In as_underlying_atomic_identifier_for_attribute_id, could not determine the data type. Type name: ${attributeDetails?.type || 'unknown'}, resolved dataType: ${JSON.stringify(dataType)}`
202+
)
194203
return null
195204
}
196205
}

src-electron/generator/helper-c.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const queryZcl = require('../db/query-zcl.js')
2525
const queryPackage = require('../db/query-package.js')
2626
const templateUtil = require('./template-util.js')
2727
const bin = require('../util/bin')
28-
const types = require('../util/types.js')
2928
const string = require('../util/string')
3029
const _ = require('lodash')
3130
const dbEnum = require('../../src-shared/db-enum.js')
@@ -135,6 +134,9 @@ async function asUnderlyingTypeHelper(dataType, context, packageIds) {
135134
) {
136135
return context.global.overridable.stringType()
137136
} else {
137+
envConfig.logError(
138+
`In asUnderlyingTypeHelper, could not determine the data type. This might be due to an unknown type passed to asUnderlyingType. Received: ${JSON.stringify(dataType)}`
139+
)
138140
return 'uint8_t *'
139141
}
140142
} catch (err) {

src-electron/generator/helper-zigbee-zcl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
const queryZcl = require('../db/query-zcl')
2525
const dbEnum = require('../../src-shared/db-enum')
2626
const templateUtil = require('./template-util')
27+
const envConfig = require('../util/env')
2728

2829
/**
2930
*
@@ -113,6 +114,9 @@ async function zcl_command_argument_type_to_cli_data_type_util(
113114
) {
114115
return cliPrefix + '_STRING' + optionalArgumentExtension
115116
} else {
117+
envConfig.logError(
118+
`In zcl_command_argument_type_to_cli_data_type_util, could not determine the data type for ${JSON.stringify(dataType)}`
119+
)
116120
return ''
117121
}
118122
} else {

src-electron/generator/matter/controller/python/templates/helper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const dbEnum = require('../../../../../../src-shared/db-enum');
2121
const ChipTypesHelper = require('../../../app/zap-templates/common/ChipTypesHelper');
2222
const templateUtil = require(zapPath + 'generator/template-util.js');
2323
const queryZcl = require(zapPath + 'db/query-zcl');
24+
const envConfig = require(zapPath + 'util/env');
2425

2526
const characterStringTypes = ['CHAR_STRING', 'LONG_CHAR_STRING'];
2627
const octetStringTypes = ['OCTET_STRING', 'LONG_OCTET_STRING'];
@@ -104,6 +105,9 @@ async function as_underlying_python_zcl_type(type, clusterId, options) {
104105
} else if (characterStringTypes.includes(type.toUpperCase())) {
105106
return 'str';
106107
} else {
108+
envConfig.logError(
109+
`In as_underlying_python_zcl_type, could not determine the data type for type: '${type}', received dataType: ${JSON.stringify(dataType)}`
110+
);
107111
return '';
108112
}
109113
}

src-electron/util/types.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,16 @@ async function getSignAndSizeOfZclType(db, type, packageIds, options) {
401401
dataType.name
402402
)
403403
dataTypesize = Math.pow(2, Math.ceil(Math.log2(number.size)))
404+
} else {
405+
env.logError(
406+
`In getSignAndSizeOfZclType, unhandled discriminatorName '${dataType.discriminatorName}' for type '${type}': ${JSON.stringify(dataType)}`
407+
)
408+
isKnown = false
404409
}
405410
} else {
411+
env.logError(
412+
`In getSignAndSizeOfZclType, could not determine the data type for type: '${type}'`
413+
)
406414
isKnown = false
407415
}
408416
let ret = {

0 commit comments

Comments
 (0)