diff --git a/src/ifcopenshell-python/ifcopenshell/validate.py b/src/ifcopenshell-python/ifcopenshell/validate.py index 6bb00992c0..25f9b3a685 100644 --- a/src/ifcopenshell-python/ifcopenshell/validate.py +++ b/src/ifcopenshell-python/ifcopenshell/validate.py @@ -320,14 +320,16 @@ def log_internal_cpp_errors( chr_offset_re = re.compile(r"at offset (\d+)\s*") for_instance_re = re.compile(r"\s*for instance #(\d+)\s*") + for_header_ent_re = re.compile(r"\s*for header entity (\w+)") if log_content is None: log_content = ifcopenshell.get_log() msgs = list(map(json.loads, filter(None, log_content.split("\n")))) chr_offsets = [chr_offset_re.findall(m["message"]) for m in msgs] instance_messages = [for_instance_re.findall(m["message"]) for m in msgs] + header_messages = [for_header_ent_re.findall(m["message"]) for m in msgs] - if chr_offsets or (instance_messages and f is None): + if any(chr_offsets) or (any(instance_messages) and f is None): # The file is opened in binary mode, in order # to correspond with the offsets reported by # IfcOpenShell C++ @@ -348,7 +350,7 @@ def log_internal_cpp_errors( else: logger.error("For instance:\n %s\n%s", line, m) - if instance_messages: + if any(instance_messages): for instid, msg in zip(instance_messages, msgs): if instid: m = for_instance_re.sub("", msg["message"]) @@ -376,6 +378,12 @@ def log_internal_cpp_errors( else: logger.error(m) + if any(header_messages): + for hent, msg in zip(header_messages, msgs): + if hent: + m = msg["message"] + logger.error(m) + entity_attribute_map: dict[tuple[str, str], tuple[entity_type, tuple[attribute, ...]]] = {} diff --git a/src/ifcparse/IfcFile.cpp b/src/ifcparse/IfcFile.cpp index 93525f3bcf..d0b2dd030e 100644 --- a/src/ifcparse/IfcFile.cpp +++ b/src/ifcparse/IfcFile.cpp @@ -259,7 +259,11 @@ IfcEntityInstanceData IfcParse::parse_context::construct(boost::optional expected_size && *expected_size != tokens_.size()) { size_t expected = expected_size ? *expected_size : parameter_types.size(); - Logger::Warning("Expected " + std::to_string(expected) + " attribute values, found " + std::to_string(tokens_.size()) + (name ? std::string(" for instance #" + std::to_string(*name)) : std::string(""))); + if (decl != nullptr && decl->schema() == &Header_section_schema::get_schema()) { + Logger::Warning("Expected " + std::to_string(expected) + " attribute values, found " + std::to_string(tokens_.size()) + " for header entity " + decl->name()); + } else { + Logger::Warning("Expected " + std::to_string(expected) + " attribute values, found " + std::to_string(tokens_.size()) + (name ? std::string(" for instance #" + std::to_string(*name)) : std::string(""))); + } } if (tokens_.empty()) {