@@ -510,21 +510,30 @@ Given file pattern: ')END"
510510 auto newType = const_cast <Access *>(&IOHandler ()->m_frontendAccess );
511511 *newType = Access::READ_WRITE;
512512
513- if (input->iterationEncoding == IterationEncoding::fileBased)
514- readFileBased ();
515- else
516- readGorVBased ();
517-
518- if (series.iterations .empty ())
513+ try
519514 {
520- /* Access::READ_WRITE can be used to create a new Series
521- * allow setting attributes in that case */
522- written () = false ;
523515
524- initDefaults (input->iterationEncoding );
525- setIterationEncoding (input->iterationEncoding );
516+ if (input->iterationEncoding == IterationEncoding::fileBased)
517+ readFileBased ();
518+ else
519+ readGorVBased ();
526520
527- written () = true ;
521+ if (series.iterations .empty ())
522+ {
523+ /* Access::READ_WRITE can be used to create a new Series
524+ * allow setting attributes in that case */
525+ written () = false ;
526+
527+ initDefaults (input->iterationEncoding );
528+ setIterationEncoding (input->iterationEncoding );
529+
530+ written () = true ;
531+ }
532+ }
533+ catch (...)
534+ {
535+ *newType = oldType;
536+ throw ;
528537 }
529538
530539 *newType = oldType;
@@ -1100,13 +1109,14 @@ void Series::readGorVBased(bool do_init)
11001109 IOHandler ()->flush (internal::defaultFlushParams);
11011110
11021111 /*
1103- * Return true when iteration is parsed successfully .
1112+ * Return error if one is caught .
11041113 */
1105- auto readSingleIteration = [&series, &pOpen, this ](
1106- uint64_t index,
1107- std::string path,
1108- bool guardAgainstRereading,
1109- bool beginStep) -> bool {
1114+ auto readSingleIteration =
1115+ [&series, &pOpen, this ](
1116+ uint64_t index,
1117+ std::string path,
1118+ bool guardAgainstRereading,
1119+ bool beginStep) -> std::optional<error::ReadError> {
11101120 if (series.iterations .contains (index))
11111121 {
11121122 // maybe re-read
@@ -1115,7 +1125,7 @@ void Series::readGorVBased(bool do_init)
11151125 // reparsing is not needed
11161126 if (guardAgainstRereading && i.written ())
11171127 {
1118- return true ;
1128+ return {} ;
11191129 }
11201130 if (i.get ().m_closed != internal::CloseStatus::ParseAccessDeferred)
11211131 {
@@ -1142,7 +1152,7 @@ void Series::readGorVBased(bool do_init)
11421152 << " ' and will skip it due to read error:\n "
11431153 << err.what () << std::endl;
11441154 series.iterations .container ().erase (index);
1145- return false ;
1155+ return {err} ;
11461156 }
11471157 i.get ().m_closed = internal::CloseStatus::Open;
11481158 }
@@ -1151,7 +1161,7 @@ void Series::readGorVBased(bool do_init)
11511161 i.get ().m_closed = internal::CloseStatus::ParseAccessDeferred;
11521162 }
11531163 }
1154- return true ;
1164+ return {} ;
11551165 };
11561166
11571167 switch (iterationEncoding ())
@@ -1173,11 +1183,15 @@ void Series::readGorVBased(bool do_init)
11731183 {
11741184 index = series.iterations .getAttribute (" snapshot" ).get <uint64_t >();
11751185 }
1176- if (! readSingleIteration (index, " " , false , true ))
1186+ if (auto err = readSingleIteration (index, " " , false , true ); err )
11771187 {
1178- throw error::ParseError (
1179- " In variable-based iteration encoding, read errors in the "
1180- " first iteration are not recoverable (see warnings above)." );
1188+ /*
1189+ * Cannot recover from errors in this place.
1190+ * If there is an error in the first iteration, the Series cannot
1191+ * be read in variable-based encoding.
1192+ * The read API will try to skip other iterations that have errors.
1193+ */
1194+ throw *err;
11811195 }
11821196 break ;
11831197 }
0 commit comments