From 5fada6fbc39af406c18e98f05a0d454861ce1f59 Mon Sep 17 00:00:00 2001
From: Xavier Robin <xavier.robin@unibas.ch>
Date: Fri, 18 Aug 2023 11:57:13 +0200
Subject: [PATCH] fix: report file errors with message and exit code

---
 modules/conop/src/chemdict_tool.cc | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/modules/conop/src/chemdict_tool.cc b/modules/conop/src/chemdict_tool.cc
index 0286e525f..404f50b8a 100644
--- a/modules/conop/src/chemdict_tool.cc
+++ b/modules/conop/src/chemdict_tool.cc
@@ -66,6 +66,11 @@ int main(int argc, char const *argv[])
   }
   boost::iostreams::filtering_stream<boost::iostreams::input>  filtered_istream;  
   std::ifstream istream(argv[2]);
+  if (! istream.is_open()) {
+      std::cout << "Cannot open " << argv[2] << ": [Errno " << errno << "] "
+                << strerror(errno) << std::endl;
+      return 1;
+  }
   if (boost::iequals(".gz", boost::filesystem::extension(argv[2]))) {
     filtered_istream.push(boost::iostreams::gzip_decompressor());
   }
@@ -92,6 +97,11 @@ int main(int argc, char const *argv[])
   cdp.SetCompoundLib(in_mem_lib);
   cdp.Parse();
   in_mem_lib->SetChemLibInfo();
-  in_mem_lib->Copy(argv[3]);  
+  conop::CompoundLibPtr copy = in_mem_lib->Copy(argv[3]);
+  if (! copy) {
+      std::cout << "Cannot save " << argv[3] << ": [Errno " << errno << "] "
+                << strerror(errno) << std::endl;
+      return 1;
+  }
   return 0;
 }
-- 
GitLab