Skip to content

Commit

Permalink
ENH: Update error messages from DataArrayIO and StringArrayIO (#901)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Mar 31, 2024
1 parent 7021f18 commit d769fce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/simplnx/DataStructure/IO/HDF5/DataArrayIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ class DataArrayIO : public IDataIO
auto datasetReader = parentGroup.openDataset(dataArrayName);
if(!datasetReader.isValid())
{
std::string ss = "Could not open Dataset";
std::string ss = fmt::format("Could not open data set '{}' which is a child of '{}'", dataArrayName, parentGroup.getName());
return MakeErrorResult(-900, ss);
}

nx::core::HDF5::Type type = datasetReader.getType();
if(type == nx::core::HDF5::Type::unknown)
{
std::string ss = "Invalid Dataset data type";
std::string ss = fmt::format("Invalid Dataset data type for DataArray '{}' which is a child of '{}'", dataArrayName, parentGroup.getName());
return MakeErrorResult(-901, ss);
}

auto dataTypeAttribute = datasetReader.getAttribute(Constants::k_ObjectTypeTag);
const bool isBoolArray = (dataTypeAttribute.isValid() && dataTypeAttribute.readAsString().compare("DataArray<bool>") == 0);

// Check importablility
// Check ability to import the data
auto importableAttribute = datasetReader.getAttribute(Constants::k_ImportableTag);
if(importableAttribute.isValid() && importableAttribute.readAsValue<int32>() == 0)
{
Expand Down Expand Up @@ -133,8 +133,7 @@ class DataArrayIO : public IDataIO

if(err < 0)
{
std::string ss = "Error importing DataArray";
return MakeErrorResult(err, ss);
return MakeErrorResult(err, fmt::format("Error importing dataset from HDF5 file. DataArray name '{}' that is a child of '{}'", dataArrayName, parentGroup.getName()));
}

return {};
Expand Down
8 changes: 4 additions & 4 deletions src/simplnx/DataStructure/IO/HDF5/StringArrayIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Result<> StringArrayIO::readData(DataStructureReader& dataStructureReader, const
auto datasetReader = parentGroup.openDataset(objectName);
std::string dataArrayName = datasetReader.getName();

// Check importablility
// Check ability to import the data
auto importableAttribute = datasetReader.getAttribute(Constants::k_ImportableTag);
if(importableAttribute.isValid() && importableAttribute.readAsValue<int32>() == 0)
{
Expand All @@ -46,8 +46,7 @@ Result<> StringArrayIO::readData(DataStructureReader& dataStructureReader, const

if(data == nullptr)
{
std::string ss = "Error importing DataArray";
return MakeErrorResult(-404, ss);
return MakeErrorResult(-404, fmt::format("Error importing DataArray with name '{}' that is a child of group '{}'", dataArrayName, parentGroup.getName()));
}

return {};
Expand All @@ -71,7 +70,8 @@ Result<> StringArrayIO::writeData(DataStructureWriter& dataStructureWriter, cons
result = tupleDimsAttribWriter.writeValue<uint64>(dataArray.size());
if(result.invalid())
{
std::string ss = fmt::format("Error writing DataObject attribute: {}", k_TupleDimsAttrName);
std::string ss =
fmt::format("Error writing DataObject attribute: {} for DataArray with name '{}' which has a parent named '{}'", k_TupleDimsAttrName, dataArray.getName(), parentGroup.getName());
return MakeErrorResult(result.errors()[0].code, ss);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/simplnx/DataStructure/IO/HDF5/StringArrayIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SIMPLNX_EXPORT StringArrayIO : public IDataIO
using data_type = StringArray;

StringArrayIO();
virtual ~StringArrayIO() noexcept;
~StringArrayIO() noexcept override;

StringArrayIO(const StringArrayIO& other) = delete;
StringArrayIO(StringArrayIO&& other) = delete;
Expand All @@ -36,7 +36,7 @@ class SIMPLNX_EXPORT StringArrayIO : public IDataIO
* @return Result<>
*/
Result<> readData(DataStructureReader& dataStructureReader, const group_reader_type& parentGroup, const std::string& arrayName, DataObject::IdType importId,
const std::optional<DataObject::IdType>& parentId, bool useEmptyDataStore = false) const override;
const std::optional<DataObject::IdType>& parentId, bool useEmptyDataStore) const override;

/**
* @brief Attempts to write an StringArray to HDF5.
Expand Down

0 comments on commit d769fce

Please sign in to comment.