From c38c82a12a9c75bd8f0e4d7eb54422ef1b62717b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Tue, 11 Apr 2023 11:46:49 +0200 Subject: [PATCH] Accept undefined dataset as long as no chunks are written yet Just ignore and skip the component in that case --- src/RecordComponent.cpp | 18 +++++++++++++++--- src/backend/PatchRecordComponent.cpp | 20 ++++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/RecordComponent.cpp b/src/RecordComponent.cpp index 1b909d3ab3..a54373be59 100644 --- a/src/RecordComponent.cpp +++ b/src/RecordComponent.cpp @@ -242,9 +242,21 @@ void RecordComponent::flush( */ if (!rc.m_dataset.has_value()) { - throw error::WrongAPIUsage( - "[RecordComponent] Must specify dataset type and extent before " - "flushing (see RecordComponent::resetDataset())."); + // The check for !written() is technically not needed, just + // defensive programming against internal bugs that go on us. + if (!written() && rc.m_chunks.empty()) + { + // No data written yet, just accessed the object so far without + // doing anything + // Just do nothing and skip this record component. + return; + } + else + { + throw error::WrongAPIUsage( + "[RecordComponent] Must specify dataset type and extent " + "before flushing (see RecordComponent::resetDataset())."); + } } if (!written()) { diff --git a/src/backend/PatchRecordComponent.cpp b/src/backend/PatchRecordComponent.cpp index 9e51994800..c418eb5fed 100644 --- a/src/backend/PatchRecordComponent.cpp +++ b/src/backend/PatchRecordComponent.cpp @@ -104,10 +104,22 @@ void PatchRecordComponent::flush( { if (!rc.m_dataset.has_value()) { - throw error::WrongAPIUsage( - "[PatchRecordComponent] Must specify dataset type and extent " - "before " - "flushing (see RecordComponent::resetDataset())."); + // The check for !written() is technically not needed, just + // defensive programming against internal bugs that go on us. + if (!written() && rc.m_chunks.empty()) + { + // No data written yet, just accessed the object so far without + // doing anything + // Just do nothing and skip this record component. + return; + } + else + { + throw error::WrongAPIUsage( + "[PatchRecordComponent] Must specify dataset type and " + "extent before flushing (see " + "RecordComponent::resetDataset())."); + } } if (!written()) {