Skip to content

createFromIfcStoreys throws TypeError when a storey has no Name/Elevation attribute #806

Description

@osama-ata

Description

Views.createFromIfcStoreys throws instead of skipping when an IFCBUILDINGSTOREY item has no Name (or no Elevation) attribute at all.

if (!("value" in storey.Name && "value" in storey.Elevation)) {

for (const storey of storeysData) {
  if (!("value" in storey.Name && "value" in storey.Elevation)) {
    continue;
  }
  ...

When storey.Name (or storey.Elevation) is undefined — which happens for a storey item that has no Name/Elevation attribute in the source IFC — "value" in storey.Name throws:

TypeError: Cannot use 'in' operator to search for 'value' in undefined

instead of just failing the guard and being skipped via continue, as the code clearly intends.

This is reproducible against the currently published 3.4.8 (same code on main as of the commit linked above, package.json still reads 3.4.0).

Reproduction

Load any IFC model containing a BUILDINGSTOREY whose Name (or Elevation) attribute is absent, then call:

await views.createFromIfcStoreys();

This throws a TypeError instead of skipping the malformed storey.

Suggested fix

Short-circuit correctly instead of relying on && to protect the second in check when the first operand can itself be undefined:

for (const storey of storeysData) {
  if (!(storey.Name && "value" in storey.Name && storey.Elevation && "value" in storey.Elevation)) {
    continue;
  }
  ...

Environment

  • @thatopen/components 3.4.8 (also present on main)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions