1. Marcin Kasperski
  2. mekk.fics

Commits

Marcin Kasperski  committed b5c23eb

Tell command parsing exceptions contain command name as .command if it is known

  • Participants
  • Parent commits 65f0d49
  • Branches default

Comments (0)

Files changed (3)

File sample/clock_statistician.py

View file
         try:
             base, inc = int(args[0]), int(args[1])
         except ValueError:
-            raise tell_errors.InvalidCommandParameters()
+            raise tell_errors.InvalidCommandParameters(self.name())
         stat = yield self.clock_statistician.stat_clock(base, inc)
         # Alternative reply method
         yield fics_client.tell_to(player, "I spotted %s games played with %s %s clock" % (

File src/mekk/fics/tell_commands/command_parser.py

View file
                         name=self.params_resolvers[command_name].resolve(name)
                     except tell_errors.ShortcutAmbiguousKeyword as e:
                         raise tell_errors.AmbiguousCommandParameter(
-                            e.bad_keyword, e.matching_keywords)
+                            command_name, e.bad_keyword, e.matching_keywords)
                     except tell_errors.ShortcutUnknownKeyword as e:
                         raise tell_errors.UnknownCommandParameter(
-                            e.bad_keyword, e.known_keywords)
+                            command_name, e.bad_keyword, e.known_keywords)
                 #kwargs[name] = value
                 kwargs.append( (name, value) )
             else:
         pos_max = self.max_positional_params_count[command_name]
         if len(args) < pos_min:
             raise tell_errors.BadFreeParametersCount(
-                len(args), pos_min, pos_max)
+                command_name, len(args), pos_min, pos_max)
         if pos_max is not None:
             if len(args) > pos_max:
                 raise tell_errors.BadFreeParametersCount(
-                    len(args), pos_min, pos_max)
+                    command_name, len(args), pos_min, pos_max)
         return command_name, args, kwargs
 
     def resolve_command_name(self, command_name):

File src/mekk/fics/tell_commands/tell_errors.py

View file
 class InvalidCommandParameters(InvalidTellCommand):
     """General command parameters error."""
     user_msg = "Invalid command parameters"
+    def __init__(self, command):
+        self.command = command
 
 class UnknownCommandParameter(InvalidCommandParameters):
     """Thrown when some unknown parameter is used."""
-    def __init__(self, bad_param, known_params):
+    def __init__(self, command, bad_param, known_params):
+        super(UnknownCommandParameter, self).__init__(command)
         self.bad_param = bad_param
         self.known_params = known_params
         self.user_msg = "Unknown parameter: %s (expected one of: %s)" % (
 
 class AmbiguousCommandParameter(InvalidCommandParameters):
     """Thrown when some param name is shortened too much"""
-    def __init__(self, given_param, matching_params_list):
+    def __init__(self, command, given_param, matching_params_list):
+        super(InvalidCommandParameters, self).__init__(command)
         self.given_param = given_param
         self.matching_params = matching_params_list
         self.user_msg = "Ambiguous parameter %s. Which do you mean: %s?" % (
 
 class BadFreeParametersCount(InvalidCommandParameters):
     """Thrown when there are too many or not enough non-named params"""
-    def __init__(self, given, min, max):
+    def __init__(self, command, given, min, max):
         """ Good is min <= given < max
         """
+        super(BadFreeParametersCount, self).__init__(command)
         self.min_count = min
         self.max_count = max
         self.given_count = given