From 492ef5936e8e3eb18658a216db0593c33a5dd35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 12 Jan 2026 11:17:53 +0100 Subject: [PATCH 1/3] Reactivate Iteration::closed() check seems to fail in some instances --- src/RecordComponent.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index eb41dddd19..28295c82f3 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -51,8 +51,10 @@ namespace internal Attributable a; a.setData(std::shared_ptr{this, [](auto const &) {}}); // this check can be too costly in some setups -#if 0 - if (a.containingIteration().closed()) +#if 1 + if ((*a.containingIteration().first.value()) + .asInternalCopyOf() + .closed()) { throw error::WrongAPIUsage( "Cannot write/read chunks to/from closed Iterations."); From c2076676c249fcae166fd2e5cd9c0b7026342fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Tue, 13 Jan 2026 11:17:32 +0100 Subject: [PATCH 2/3] Fix test --- src/RecordComponent.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index 28295c82f3..2a45e74129 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -51,10 +51,11 @@ namespace internal Attributable a; a.setData(std::shared_ptr{this, [](auto const &) {}}); // this check can be too costly in some setups -#if 1 - if ((*a.containingIteration().first.value()) - .asInternalCopyOf() - .closed()) +#if openPMD_USE_INVASIVE_TESTS + + auto &iterationData = *a.containingIteration().first.value(); + auto iteration = iterationData.asInternalCopyOf(); + if (iteration.closed() && !iterationData.allow_reopening_implicitly) { throw error::WrongAPIUsage( "Cannot write/read chunks to/from closed Iterations."); From a963d73cbdc23b7ab8811f89465960cc71f03b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 23 Jan 2026 14:21:17 +0100 Subject: [PATCH 3/3] Add a test if the RecordComponent is contained by any Iteration --- src/RecordComponent.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index 2a45e74129..c6eef23313 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -53,11 +53,18 @@ namespace internal // this check can be too costly in some setups #if openPMD_USE_INVASIVE_TESTS - auto &iterationData = *a.containingIteration().first.value(); + auto maybe_an_iteration = a.containingIteration().first; + if (!maybe_an_iteration.has_value()) + { + throw std::runtime_error( + "Trying to write to/read from a RecordComponent that is not " + "contained by any Iteration."); + } + auto &iterationData = *maybe_an_iteration.value(); auto iteration = iterationData.asInternalCopyOf(); if (iteration.closed() && !iterationData.allow_reopening_implicitly) { - throw error::WrongAPIUsage( + throw std::runtime_error( "Cannot write/read chunks to/from closed Iterations."); } #endif