From 0d7439c7a59f684a3614e2291e56f50d36520f82 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 25 Mar 2025 17:06:53 +0500 Subject: [PATCH] ifcopenshell.validate to catch invalid entities used in entities attributes #6409 Example ``` For instance: # 1 =IFCCARTESIANPOINT((5.,5.,nan.)); Entity with name 'nan.' not found in schema 'IFC4' ``` --- .../validate/fail-invalid-entity-in-attribute.ifc | 10 ++++++++++ src/ifcparse/IfcParse.cpp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity-in-attribute.ifc diff --git a/src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity-in-attribute.ifc b/src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity-in-attribute.ifc new file mode 100644 index 0000000000..39ec2029e6 --- /dev/null +++ b/src/ifcopenshell-python/test/fixtures/validate/fail-invalid-entity-in-attribute.ifc @@ -0,0 +1,10 @@ +ISO-10303-21; +HEADER; +FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1'); +FILE_NAME('','2022-10-01T16:31:47',(''),(''),'IfcOpenShell 0.7.0','IfcOpenShell 0.7.0',''); +FILE_SCHEMA(('IFC4')); +ENDSEC; +DATA; +#1=IFCCARTESIANPOINT((5.,5.,nan.)); +ENDSEC; +END-ISO-10303-21; diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 021b9a1099..f1a9237d57 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -726,7 +726,7 @@ void IfcParse::IfcFile::load(unsigned entity_instance_name, const IfcParse::enti context.push(simple_type_instance); simple_type_instance->file_ = this; } catch (IfcException& e) { - Logger::Message(Logger::LOG_ERROR, e.what()); + Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + " at offset " + std::to_string(next.startPos)); // #4070 We didn't actually capture an aggregate entry, undo length increment. return_value--; }