Commits

Jürgen Bömmels committed dc37076

Improve error message of WrongArgsNumber: Add actual and expected values

  • Participants
  • Parent commits e5146e1

Comments (0)

Files changed (2)

File scheme/object.py

 
 class WrongArgsNumber(SchemeException):
     def __str__(self):
-        return "Wrong number of args"
+        if len(self.args) == 2:
+            return ("Wrong number of args. Got: %d, expected: %s" %
+                (self.args[0], self.args[1]))
+        else:
+            return "Wrong number of args."
 
 class WrongArgType(SchemeException):
     def __str__(self):

File scheme/procedure.py

     def procedure(self, ctx, lst):
         if len(lst) == 0:
             if self.default_result is None:
-                raise WrongArgsNumber()
+                raise WrongArgsNumber(len(lst), ">1")
 
             return self.default_result
 
 
     def procedure(self, ctx, lst):
         if len(lst) != 2:
-            raise WrongArgsNumber()
+            raise WrongArgsNumber(len(lst), 2)
         
         w_car = lst[0]
         w_cdr = lst[1]
 class CarCdrCombination(W_Procedure):
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
         w_pair = lst[0]
         return self.do_oper(w_pair)
 
 
     def procedure_tr(self, ctx, lst):
         if len(lst) != 2:
-            raise WrongArgsNumber
-
+            raise WrongArgsNumber(len(lst), 2)
+        
         (w_procedure, w_lst) = lst
         if not isinstance(w_procedure, W_Procedure):
             #print w_procedure.to_repr(), "is not a procedure"
 
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
 
         w_promise = lst[0]
         if not isinstance(w_promise, W_Promise):
 
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
         w_inlist = lst[0]
         w_outlist = w_nil
         while w_inlist is not w_nil:
 
     def procedure_tr(self, ctx, lst):
         if len(lst) < 2:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), ">2")
 
         w_proc = lst[0]
         if not isinstance(w_proc, W_Procedure):
 
     def procedure(self, ctx, lst):
         if len(lst) < 1 or len(lst) > 2:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), "1-2")
 
         w_number = lst[0]
         if not isinstance(w_number, W_Integer):
 class AssocX(W_Procedure):
     def procedure(self, ctx, lst):
         if len(lst) != 2:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 2)
 
         (w_obj, w_alst) = lst
 
 class MemX(W_Procedure):
     def procedure(self, ctx, lst):
         if len(lst) != 2:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 2)
 
         (w_obj, w_lst) = lst
 
 class EquivalnecePredicate(W_Procedure):
     def procedure(self, ctx, lst):
         if len(lst) != 2:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 2)
         (a, b) = lst
         return W_Boolean(self.predicate(a, b))
 
 class PredicateNumber(W_Procedure):
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
 
         w_obj = lst[0]
         if not isinstance(w_obj, W_Number):
 
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
 
         w_obj = lst[0]
         if not isinstance(w_obj, W_Number):
 class TypePredicate(W_Procedure):
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
 
         return W_Boolean(self.predicate(lst[0]))
 
 
     def procedure(self, ctx, lst):
         if len(lst) != 1:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 1)
 
         w_bool = lst[0]
         if w_bool.to_boolean():
             (obj, port) = lst
             raise NotImplementedError
         else:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), "1-2")
 
         print obj.to_string(),
         return w_undefined
 
     def procedure(self, ctx, lst):
         if len(lst) != 0:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), 0)
 
         print
         return w_undefined
             (obj, port) = lst
             raise NotImplementedError
         else:
-            raise WrongArgsNumber
+            raise WrongArgsNumber(len(lst), "1-2")
 
         print obj.to_repr(),
         return w_undefined