changeset 23165:5291b67ff124

More verbose information when inputParser fails validating argument (patch #9241) * scripts/general/inputParser.m: Next to the invalid parameter also print the function which caused invalidation to guide the user to fix the input. New regression test. Pushed by Kai T. Ohlhus <k.ohlhus@gmail.com>.
author Georg Wiora
date Wed, 08 Feb 2017 11:34:18 +0100
parents 99ca557fd34f
children ea4c27f49a62
files scripts/general/inputParser.m
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/inputParser.m	Wed Feb 08 10:41:56 2017 +0100
+++ b/scripts/general/inputParser.m	Wed Feb 08 11:34:18 2017 +0100
@@ -419,8 +419,9 @@
             vidx -= 1;
             break
           else
-            this.error (sprintf ("failed validation of %s",
-                                 toupper (opt.name)));
+            this.error (sprintf (["failed validation of %s\n", ...
+                                  "Validation function: %s"],
+                                 toupper (opt.name), disp(opt.val)));
           endif
         endif
         this.Results.(opt.name) = in;
@@ -503,7 +504,8 @@
 
     function validate_arg (this, name, val, in)
         if (! val (in))
-          this.error (sprintf ("failed validation of %s", toupper (name)));
+          this.error (sprintf ("failed validation of %s with %s",
+                               toupper (name), func2str (val)));
         endif
         this.Results.(name) = in;
     endfunction
@@ -752,3 +754,9 @@
 %! p.parse ("b", 1);
 %! assert (p.Results, struct ("b", 1));
 %! assert (p.Unmatched, struct ());
+
+## Test for patch #9241
+%!error<failed validation of A with ischar>
+%! p = inputParser;
+%! p.addParameter ("a", [], @ischar);
+%! p.parse ("a", 1);