Commit 3b65344
fix(types): populate reverse mapping in cluster enum runtime objects (#3666)
* fix(types): populate reverse mapping in cluster enum runtime objects
Cluster `.d.ts` files declare `NodeOperationalCertStatus` etc. as TypeScript
numeric enums, which would carry value→name reverse mapping at runtime. The
matter.js runtime equivalent built by `EnumForValueModel` only populated
forward (name→value) entries, so `Cluster.SomeEnum[code]` returned `undefined`.
This produced useless logs like
Commission error for "updateFabricLabel": undefined (10), undefined
(reported as matterjs-server#581). Reverse mapping now matches the declared
TS shape so generic diagnostic call sites can resolve a member name from a
numeric code.
Also:
- `StatusResponseError.is()` becomes a `error is StatusResponseError` type
guard. Body still uses `of()` so cause-chain matching is preserved.
- ControllerCommissioningFlow: drop the unreachable `LabelConflict` branch
inside the `addNoc` block (AddNoc has no Label argument and cannot return
this status per spec). Add a matching branch for `updateFabricLabel`,
throwing `FabricLabelConflictError` with a descriptive message that names
the conflicting label.
- CommissioningController.validateAndUpdateFabricLabel: detect a
`LabelConflict` `clusterCode` via `StatusResponseError.of()` and surface
`FabricLabelConflictError` with the same wording so post-commission label
updates produce the same actionable error as the commissioning-time path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(types): tighten EnumForValueModel return type, drop is() type guard
Address PR review feedback:
- Replace `Record<string, string | number>` with `EnumLikeObject` =
`{ [k: string]: number } & { [k: number]: string }`. Forward lookups by
name remain `number`; reverse lookups by id are `string`. Restores the
numeric-enum typing that external callers relied on.
- Revert `StatusResponseError.is()` to `boolean` return. Type-guarding to
`error is StatusResponseError` was a partial lie because the body uses
`of()` which matches the cause chain — for wrappers the original `error`
is not actually an SRE. Callers needing the matched instance should use
`StatusResponseError.of(error)` directly.
- Add unit tests covering forward, reverse, and unknown-key lookups against
`OperationalCredentials.NodeOperationalCertStatus` to lock in the runtime
enum shape.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 07a8a29 commit 3b65344
4 files changed
Lines changed: 61 additions & 16 deletions
File tree
- packages
- matter.js/src
- protocol/src/peer
- types
- src/cluster
- test/cluster
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
908 | 911 | | |
909 | 912 | | |
910 | 913 | | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
915 | 928 | | |
916 | 929 | | |
917 | 930 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | 596 | | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
601 | 604 | | |
602 | 605 | | |
603 | 606 | | |
| |||
1254 | 1257 | | |
1255 | 1258 | | |
1256 | 1259 | | |
1257 | | - | |
1258 | 1260 | | |
1259 | 1261 | | |
1260 | 1262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
10 | 15 | | |
11 | 16 | | |
12 | | - | |
| 17 | + | |
13 | 18 | | |
14 | | - | |
15 | | - | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
19 | | - | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | | - | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| 33 | + | |
29 | 34 | | |
30 | 35 | | |
31 | 36 | | |
32 | | - | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments