فهرست منبع

improved errors description

avkonst 11 سال پیش
والد
کامیت
bd66739bae
3فایلهای تغییر یافته به همراه12 افزوده شده و 10 حذف شده
  1. 4 4
      mainline/mpp/dbf.py
  2. 1 1
      mainline/mpp/internal/loader.py
  3. 7 5
      mainline/mpp/warn.py

+ 4 - 4
mainline/mpp/dbf.py

@@ -45,7 +45,7 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
         self.dbfile_prev = options.__dict__['db_file_prev']
         
         if self.dbfile_prev != None and os.path.exists(self.dbfile_prev) == False:
-            self.parser.error("File does not exist:" + self.dbfile_prev)
+            self.parser.error("option --db-file-prev: File '{0}' does not exist".format(self.dbfile_prev))
 
         
     def initialize(self):
@@ -61,16 +61,16 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
             self.loader = mpp.api.Loader()
             created = self.loader.create_database(self.dbfile, previous_db = self.dbfile_prev)
             if created == False:
-                self.parser.error("Failure in creating file: " + self.dbfile)
+                self.parser.error("option --db-file: Can not create file '{0}'".format(self.dbfile))
             
         else:
             self.loader = mpp.api.Loader()
             if self.loader.open_database(self.dbfile) == False:
-                self.parser.error("Can not open file: " + self.dbfile)
+                self.parser.error("option --db-file: Can not open file '{0}'".format(self.dbfile))
             self.loader_prev = mpp.api.Loader()
             if self.dbfile_prev != None:
                 if self.loader_prev.open_database(self.dbfile_prev) == False:
-                    self.parser.error("Can not open file: " + self.dbfile_prev)
+                    self.parser.error("option --db-file-prev: Can not open file '{0}'".format(self.dbfile_prev))
                 self._warn_on_metadata()
 
     def _warn_on_metadata(self):

+ 1 - 1
mainline/mpp/internal/loader.py

@@ -164,7 +164,7 @@ class Loader(object):
         if command.strip() == "":
             optparser.error("Mandatory action argument required")
         if command not in inicontainer.actions:
-            optparser.error("Unknown action: {action}".format(action=command))
+            optparser.error("action {action}: Unknown command".format(action=command))
 
         self.action = command
 

+ 7 - 5
mainline/mpp/warn.py

@@ -63,7 +63,7 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
             self.mode = self.MODE_ALL
             
         if self.mode != self.MODE_ALL and options.__dict__['db_file_prev'] == None:
-            self.parser.error("The mode '" + options.__dict__['warn_mode'] + "' for 'general.warn' option requires '--db-file-prev' option set")
+            self.parser.error("option --warn-mode: The mode '" + options.__dict__['warn_mode'] + "' requires '--db-file-prev' option set")
 
         class Limit(object):
             def __init__(self, limit_type, limit, namespace, field, db_filter):
@@ -82,14 +82,14 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
             for each in options.__dict__['max_limit']:
                 match = re.match(pattern, each)
                 if match == None:
-                    self.parser.error("Invalid format of the '--max-limit' option: " + each)
+                    self.parser.error("option --max-limit: Invalid format: " + each)
                 limit = Limit("max", float(match.group(3)), match.group(1), match.group(2), (match.group(2), '>', float(match.group(3))))
                 self.limits.append(limit)
         if options.__dict__['min_limit'] != None:
             for each in options.__dict__['min_limit']:  
                 match = re.match(pattern, each)
                 if match == None:
-                    self.parser.error("Invalid format of the '--min-limit' option: " + each)
+                    self.parser.error("option --min-limit: Invalid format: " + each)
                 limit = Limit("min", float(match.group(3)), match.group(1), match.group(2), (match.group(2), '<', float(match.group(3))))
                 self.limits.append(limit)
     
@@ -106,7 +106,8 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
             valid.append(each)
         for each in self.limits:
             if each.namespace not in valid:
-                self.parser.error("Invalid limit option (namespace does not exist): " + each.namespace)
+                self.parser.error("option --{0}-limit: metric '{1}:{2}' is not available in the database file.".
+                                  format(each.type, each.namespace, each.field))
 
     def _verify_fields(self, namespace, valid_fields):
         valid = []
@@ -115,7 +116,8 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
         for each in self.limits:
             if each.namespace == namespace:
                 if each.field not in valid:
-                    self.parser.error("Invalid limit option (field does not exist): " + each.namespace + ":" + each.field)
+                    self.parser.error("option --{0}-limit: metric '{1}:{2}' is not available in the database file.".
+                                      format(each.type, each.namespace, each.field))
                     
     def iterate_limits(self):
         for each in self.limits: