diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index eb41dddd19..c6eef23313 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -51,10 +51,20 @@ 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 openPMD_USE_INVASIVE_TESTS + + auto maybe_an_iteration = a.containingIteration().first; + if (!maybe_an_iteration.has_value()) { - throw error::WrongAPIUsage( + 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 std::runtime_error( "Cannot write/read chunks to/from closed Iterations."); } #endif