From 805c7606a0ba910c8e04a4d95b98df02b59b1feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Mon, 22 Apr 2024 15:14:51 +0200 Subject: [PATCH] Print a hint on what might be wrong when retrieveSeries fails (#1610) * Print a hint on what might be wrong when retrieveSeries fails * add parentheses --- src/backend/Attributable.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/backend/Attributable.cpp b/src/backend/Attributable.cpp index 2388b1726d..c50ca5345d 100644 --- a/src/backend/Attributable.cpp +++ b/src/backend/Attributable.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace openPMD { @@ -126,8 +127,17 @@ Series Attributable::retrieveSeries() const { findSeries = findSeries->parent; } - auto seriesData = &auxiliary::deref_dynamic_cast( - findSeries->attributable); + auto *seriesData = + dynamic_cast(findSeries->attributable); + if (!seriesData) + { + throw std::runtime_error( + "[Attributable::retrieveSeries] Error when trying to retrieve the " + "Series object. Note: An instance of the Series object must still " + "exist when flushing. A common cause for this error is using a " + "flush call on a handle (e.g. `Iteration::seriesFlush()`) when the " + "original Series object has already gone out of scope."); + } Series res; res.setData( std::shared_ptr{seriesData, [](auto const *) {}});