Skip to content

Commit d04f607

Browse files
committed
Make namespace deserialization more resilient
Similar to #35
1 parent 6e6d250 commit d04f607

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Management clusters are no longer selected by default after retrieving clusters from an MCC instance. They are typically of less interest. They can still be selected and added along with any other cluster, however.
88
- Some notification messages have been shortened to make them quicker to read.
99
- Made the cluster deserialization process more resilient (fixes #35).
10+
- Made the namespace deserialization process more resilient (similar to #35).
1011

1112
## 2.0.1
1213

src/cc/store/ClustersProvider.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@ const _deserializeNamespacesList = function (body) {
5656
return { error: strings.clustersProvider.errors.invalidNamespacePayload() };
5757
}
5858

59-
try {
60-
return { data: body.items.map((item) => new Namespace(item)) };
61-
} catch (err) {
62-
// eslint-disable-next-line no-console -- OK to show errors
63-
console.error(
64-
`[${pkg.name}/ClustersProvider._deserializeNamespacesList()] ERROR: ${err.message}`,
65-
err
66-
);
67-
return { error: strings.clustersProvider.errors.invalidNamespace() };
68-
}
59+
return {
60+
data: body.items
61+
.map((item, idx) => {
62+
try {
63+
return new Namespace(item);
64+
} catch (err) {
65+
// eslint-disable-next-line no-console -- OK to show errors
66+
console.error(
67+
`[${pkg.name}/ClustersProvider._deserializeNamespacesList()] ERROR with namespace ${idx}: ${err.message}`,
68+
err
69+
);
70+
return undefined;
71+
}
72+
})
73+
.filter((cl) => !!cl), // eliminate invalid namespaces (`undefined` items)
74+
};
6975
};
7076

7177
/**
@@ -134,7 +140,7 @@ const _deserializeClustersList = function (body) {
134140
return undefined;
135141
}
136142
})
137-
.filter((cl) => !!cl), // eliminate failed clusters (`undefined` items)
143+
.filter((cl) => !!cl), // eliminate invalid clusters (`undefined` items)
138144
};
139145
};
140146

src/strings.ts

-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ export const clustersProvider: Dict = {
156156
errors: {
157157
invalidNamespacePayload: () =>
158158
'Failed to parse namespace payload: Unexpected data format.',
159-
invalidNamespace: () =>
160-
'Encountered at least one namespace with unexpected or missing metadata.',
161159
invalidClusterPayload: () =>
162160
'Failed to parse cluster payload: Unexpected data format.',
163161
},

0 commit comments

Comments
 (0)