From e1e8f69a67e9747b7f798164c0454508479fe8b8 Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Wed, 22 Nov 2017 08:26:15 +0100
Subject: [PATCH] Adding details to some error messages

---
 src/tools/IFile.cpp | 10 ++++++----
 src/tools/OFile.cpp |  6 +++---
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/tools/IFile.cpp b/src/tools/IFile.cpp
index 7259eec5a..085c4ab92 100644
--- a/src/tools/IFile.cpp
+++ b/src/tools/IFile.cpp
@@ -48,7 +48,7 @@ size_t IFile::llread(char*ptr,size_t s) {
     if(rr<0)    err=true;
     r=rr;
 #else
-    plumed_merror("trying to use a gz file without zlib being linked");
+    plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked");
 #endif
   } else {
     r=fread(ptr,1,s,fp);
@@ -94,7 +94,7 @@ IFile& IFile::advanceField() {
         }
         done=true;
       } else if( !words.empty() ) {
-        plumed_merror(getPath() + " mismatch between number of fields in file and expected number");
+        plumed_merror("file " + getPath() + ": mismatch between number of fields in file and expected number");
       }
     }
   }
@@ -115,7 +115,7 @@ IFile& IFile::open(const std::string&path) {
 #ifdef __PLUMED_HAS_ZLIB
     gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"r");
 #else
-    plumed_merror("trying to use a gz file without zlib being linked");
+    plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked");
 #endif
   }
   if(plumed) plumed->insertFile(*this);
@@ -230,7 +230,9 @@ IFile& IFile::getline(std::string &str) {
 unsigned IFile::findField(const std::string&name)const {
   unsigned i;
   for(i=0; i<fields.size(); i++) if(fields[i].name==name) break;
-  if(i>=fields.size()) plumed_merror(name);
+  if(i>=fields.size()) {
+    plumed_merror("file " + getPath() + ": field " + name + " cannot be found");
+  }
   return i;
 }
 
diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp
index 0681444d1..2bb7a025b 100644
--- a/src/tools/OFile.cpp
+++ b/src/tools/OFile.cpp
@@ -49,7 +49,7 @@ size_t OFile::llwrite(const char*ptr,size_t s) {
 #ifdef __PLUMED_HAS_ZLIB
       r=gzwrite(gzFile(gzfp),ptr,s);
 #else
-      plumed_merror("trying to use a gz file without zlib being linked");
+      plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked");
 #endif
     } else {
       r=fwrite(ptr,1,s,fp);
@@ -301,7 +301,7 @@ OFile& OFile::open(const std::string&path) {
 #ifdef __PLUMED_HAS_ZLIB
       gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"a9");
 #else
-      plumed_merror("trying to use a gz file without zlib being linked");
+      plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked");
 #endif
     }
   } else {
@@ -313,7 +313,7 @@ OFile& OFile::open(const std::string&path) {
 #ifdef __PLUMED_HAS_ZLIB
       gzfp=(void*)gzopen(const_cast<char*>(this->path.c_str()),"w9");
 #else
-      plumed_merror("trying to use a gz file without zlib being linked");
+      plumed_merror("file " + getPath() + ": trying to use a gz file without zlib being linked");
 #endif
     }
   }
-- 
GitLab