Skip to content

Commit

Permalink
Merge pull request #74 from ami-iit/file_read_error
Browse files Browse the repository at this point in the history
Added error message when variable does not exist in file
  • Loading branch information
S-Dafarra committed Nov 6, 2023
2 parents a0daf06 + e464144 commit ec3f525
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
- Added example. It is tested in CI. [#67](https://github.com/ami-iit/matio-cpp/pull/67)
- Clarify how to install matio with conda-forge [#68](https://github.com/ami-iit/matio-cpp/pull/68)
- Support finding visit_struct in the system also if it is installed without any CMake config file [#70](https://github.com/ami-iit/matio-cpp/pull/70)
- Added error message when variable does not exist in file [#74](https://github.com/ami-iit/matio-cpp/pull/74)

## [0.2.2] - 2023-02-24
- Switch to use upstream repo of [`garbageslam/visit_struct`](https://github.com/garbageslam/visit_struct) instead of fork [`NikolausDemmel/visit_struct`](https://github.com/NikolausDemmel/visit_struct) [#58](https://github.com/ami-iit/matio-cpp/pull/58)
Expand Down
5 changes: 5 additions & 0 deletions src/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ matioCpp::Variable matioCpp::File::read(const std::string &name) const

matioCpp::Variable output((matioCpp::SharedMatvar(matVar)));

if (!output.isValid())
{
std::cerr << "[ERROR][matioCpp::File::read] Failed to read variable " << name << ". The output is not valid." <<std::endl;
}

return output;
}

Expand Down
5 changes: 5 additions & 0 deletions test/FileUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ TEST_CASE("Read")
REQUIRE_FALSE(logicalVector(1));
REQUIRE(logicalVector(2));
REQUIRE_FALSE(logicalVector(3));


matioCpp::Variable notExisting = input.read("not_existing");
REQUIRE_FALSE(notExisting.isValid());

}

TEST_CASE("Create and delete file")
Expand Down

0 comments on commit ec3f525

Please sign in to comment.