project-chip / zap

ZAP stands for ZCL Advanced Platform. It is used to configure clusters, attributes and other entities for Matter and ZigbeePro applications.
Apache License 2.0
140 stars 83 forks source link

Zap Generate in Matter fails silently #792

Open jsloth opened 2 years ago

jsloth commented 2 years ago

Zap fails to generate output file, but it doesn't give an any error.

I have learned that {{#if (zcl_command_arguments_count this.id)}} is invalid and should cause a failure, so this is regarding Zap silently failing instead of giving an error.

Following template is a simplified example of reproducing the issue.

{{#zcl_clusters}}
{{#zcl_commands_source_server}}
{{#zcl_command_arguments}}
{{#if (zcl_command_arguments_count this.id)}} //<<< This is what cause the issue
// hello world
{{/if}}
{{/zcl_command_arguments}}
{{/zcl_commands_source_server}}
{{/zcl_clusters}}

Output from when running Zap.

➜  matter_armhf git:(feature/unify-matter-bridge-zap-ucl) ✗ ./scripts/tools/zap/generate.py \
    -z third_party/zap/repo/zcl-builtin/dotdot/library.xml \
    -t silabs_examples/unify-matter-bridge/linux/zap-handlers/unify-templates.json \
    -o silabs_examples/unify-matter-bridge/linux/zap-handlers/gen \
    silabs_examples/unify-matter-bridge/unify-matter-bridge-common/unify-matter-bridge.zap
🚀 Executing: git log -1 --format={"hash": "%H","timestamp": %ct}
🔍 Git commit: 7258c6226e97809d01d694e5a756077e3538f88f from Wed Oct 12 2022 21:42:53 GMT+0200 (Central European Summer Time)
🚀 Executing: npx tsc --build ./tsconfig.json
🚀 Executing: npx copyfiles -V ./src-electron/**/*.sql ./dist/
unglobed path: ./src-electron/db/zap-schema.sql
copy from: ./src-electron/db/zap-schema.sql
copy to: dist/src-electron/db/zap-schema.sql
🚀 Executing: npx node /home/jsolesen/work/matter_armhf/third_party/zap/repo/dist/src-electron/main-process/main.js generate --unhandled-rejections=strict -z /home/jsolesen/work/matter_armhf/third_party/zap/repo/zcl-builtin/dotdot/library.xml -g /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/linux/zap-handlers/unify-templates.json -i /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/unify-matter-bridge-common/unify-matter-bridge.zap -o /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/linux/zap-handlers/gen
⇝ npm WARN⇝  exec The following package was not found and will be installed: node
Expected node versions: v14.x.x,v16.x.x
Provided node version: v18.12.1
WARNING: you are using different node version than recommended.
🔧 Using state directory: /home/jsolesen/.zap
🤖 ZAP generation started:
    🔍 input files: /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/unify-matter-bridge-common/unify-matter-bridge.zap
    🔍 output pattern: /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/linux/zap-handlers/gen
    🔍 using templates: /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/linux/zap-handlers/unify-templates.json
    🔍 using zcl data: /home/jsolesen/work/matter_armhf/third_party/zap/repo/zcl-builtin/dotdot/library.xml
    🔍 zap version: ver. 2022.10.12, featureLevel 82, commit: 7258c6226e97809d01d694e5a756077e3538f88f from 2022-10-12T19:42:53.000Z, mode: source
🕐 Setup time: 1s 57ms
👉 using input file: /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/unify-matter-bridge-common/unify-matter-bridge.zap
👉 using output destination: /home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/linux/zap-handlers/gen
🕐 File loading time: 216ms
😎 All done: 8s 445ms.
No such file or directory
clang-format error: Command '['clang-format', '-i', '/home/jsolesen/work/matter_armhf/silabs_examples/unify-matter-bridge/linux/zap-handlers/gen/ucl/zap_debug.hpp']' returned non-zero exit status 1.
brdandu commented 1 year ago

@jsloth I do not recommend doing {{#if (zcl_command_arguments_count this.id)}} because zcl_command_arguments_count returns a promise so it may end up just being if <pending promise>(Which will be true) if the promise is not resolved in time and your results may not be as expected.

For something like this there are 2 ways to approach your problem:

brdandu commented 1 year ago

This is still an issue in the template just ran across it. I can look into this.