Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-components): remove unsafe use of assert #4717

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import { max } from 'lodash';
import assert from 'assert';
import { type Fdm3dDataProvider } from '../../data-providers/Fdm3dDataProvider';

const emptyAncestorQueryResult: AncestorQueryResult = {
connections: [],
ancestorsWithSameMapping: [],
firstMappedAncestorTreeIndex: -1
};

export class RevisionFdmNodeCache {
private readonly _cogniteClient: CogniteClient;
private readonly _fdmClient: FdmSDK;
Expand Down Expand Up @@ -211,11 +217,7 @@ export class RevisionFdmNodeCache {
const ancestorMappings = await this.getMappingConnectionsForAncestors(ancestors);

if (ancestorMappings.length === 0) {
return {
connections: [],
ancestorsWithSameMapping: ancestors,
firstMappedAncestorTreeIndex: -1
};
return emptyAncestorQueryResult;
}

const connectionsWithCorrespondingTreeIndex = this.combineConnectionsWithTreeIndex(
Expand All @@ -226,6 +228,11 @@ export class RevisionFdmNodeCache {
const firstMappedAncestorTreeIndex = findLargestTreeIndex(
connectionsWithCorrespondingTreeIndex
);

if (firstMappedAncestorTreeIndex === undefined) {
return emptyAncestorQueryResult;
}

return getAncestorDataForTreeIndex(
firstMappedAncestorTreeIndex,
connectionsWithCorrespondingTreeIndex,
Expand Down Expand Up @@ -331,10 +338,8 @@ export class RevisionFdmNodeCache {

function findLargestTreeIndex(
connectionsWithTreeIndex: Array<{ connection: FdmCadConnection; treeIndex: TreeIndex }>
): TreeIndex {
const maxTreeIndex = max(connectionsWithTreeIndex.map((e) => e.treeIndex));
assert(maxTreeIndex !== undefined);
return maxTreeIndex;
): TreeIndex | undefined {
return max(connectionsWithTreeIndex.map((e) => e.treeIndex));
}

function getAncestorDataForTreeIndex(
Expand Down
Loading