Skip to content

Commit

Permalink
Make namespace deserialization more resilient
Browse files Browse the repository at this point in the history
Similar to #35
  • Loading branch information
stefcameron committed Dec 15, 2020
1 parent 6e6d250 commit d04f607
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- 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.
- Some notification messages have been shortened to make them quicker to read.
- Made the cluster deserialization process more resilient (fixes #35).
- Made the namespace deserialization process more resilient (similar to #35).

## 2.0.1

Expand Down
28 changes: 17 additions & 11 deletions src/cc/store/ClustersProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,22 @@ const _deserializeNamespacesList = function (body) {
return { error: strings.clustersProvider.errors.invalidNamespacePayload() };
}

try {
return { data: body.items.map((item) => new Namespace(item)) };
} catch (err) {
// eslint-disable-next-line no-console -- OK to show errors
console.error(
`[${pkg.name}/ClustersProvider._deserializeNamespacesList()] ERROR: ${err.message}`,
err
);
return { error: strings.clustersProvider.errors.invalidNamespace() };
}
return {
data: body.items
.map((item, idx) => {
try {
return new Namespace(item);
} catch (err) {
// eslint-disable-next-line no-console -- OK to show errors
console.error(
`[${pkg.name}/ClustersProvider._deserializeNamespacesList()] ERROR with namespace ${idx}: ${err.message}`,
err
);
return undefined;
}
})
.filter((cl) => !!cl), // eliminate invalid namespaces (`undefined` items)
};
};

/**
Expand Down Expand Up @@ -134,7 +140,7 @@ const _deserializeClustersList = function (body) {
return undefined;
}
})
.filter((cl) => !!cl), // eliminate failed clusters (`undefined` items)
.filter((cl) => !!cl), // eliminate invalid clusters (`undefined` items)
};
};

Expand Down
2 changes: 0 additions & 2 deletions src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ export const clustersProvider: Dict = {
errors: {
invalidNamespacePayload: () =>
'Failed to parse namespace payload: Unexpected data format.',
invalidNamespace: () =>
'Encountered at least one namespace with unexpected or missing metadata.',
invalidClusterPayload: () =>
'Failed to parse cluster payload: Unexpected data format.',
},
Expand Down

0 comments on commit d04f607

Please sign in to comment.