From fb6ed7d9741e7226c70d45951863ad4c0c20d5df Mon Sep 17 00:00:00 2001 From: Brad Aagaard Date: Wed, 30 Sep 2026 21:15:50 -0600 Subject: [PATCH] FIX: Improve error message when reading values from time history database fails. --- CHANGES.md | 5 +++++ libsrc/spatialdata/spatialdb/TimeHistoryIO.cc | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2c67149..c84e5f9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## main + +* **Fixed** + * Improved error message when reading values from time history database fails. + ## Version 4.0.1 (2026/08/17) * **Added** diff --git a/libsrc/spatialdata/spatialdb/TimeHistoryIO.cc b/libsrc/spatialdata/spatialdb/TimeHistoryIO.cc index b2b2301..75d3d58 100644 --- a/libsrc/spatialdata/spatialdb/TimeHistoryIO.cc +++ b/libsrc/spatialdata/spatialdb/TimeHistoryIO.cc @@ -125,7 +125,8 @@ spatialdata::spatialdb::TimeHistoryIO::read(double** ptime, double* time = (size > 0) ? new double[size] : 0; double* amplitude = (size > 0) ? new double[size] : 0; - for (size_t i = 0; i < size; ++i) { + int count = 0; + for (size_t i = 0; i < size; ++i, ++count) { buffer.str(parser.next()); buffer.clear(); buffer >> time[i]; @@ -140,7 +141,14 @@ spatialdata::spatialdb::TimeHistoryIO::read(double** ptime, } // for if (!filein.good()) { - throw std::runtime_error("Unknown error while reading."); + std::ostringstream msg; + if (count < size) { + msg << "Read " << count << " out of " << size << " points before encountering the I/O error."; + } else { + msg << "Error occurred while reading data for final point.\n" + << "Make sure that the last line with data ends with an end-of-line character."; + } // if/else + throw std::runtime_error(msg.str()); } // if delete[] *ptime;*ptime = time;