changeset 10248:48159ee9f688 octave-forge

inputParser: mention the validator so its known why argument fails
author carandraug
date Mon, 14 May 2012 08:17:51 +0000
parents 5208f7d4f654
children e88a05e8eded
files main/general/inst/@inputParser/subsref.m
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/main/general/inst/@inputParser/subsref.m	Mon May 14 08:03:43 2012 +0000
+++ b/main/general/inst/@inputParser/subsref.m	Mon May 14 08:17:51 2012 +0000
@@ -89,7 +89,7 @@
     [name, inPar.copy] = shift (inPar.copy);
     [value, args]      = shift (args);
     if ( !feval (inPar.Required.(name).validator, value) )
-      error("%sargument '%s' failed validation %s", inPar.FunctionName, name, func2str (inPar.Required.(name).validator));
+      error_invalid (inPar.FunctionName, name, inPar.Required.(name).validator);
     endif
     inPar.Results.(name) = value;
   endfor
@@ -124,7 +124,7 @@
         args = unshift (args, value);
         continue
       else
-        error("%sinvalid value for parameter '%s'", inPar.FunctionName, name);
+        error_invalid (inPar.FunctionName, name, inPar.Optional.(name).validator);
       endif
     else
       inPar.Results.(name) = value;
@@ -175,7 +175,7 @@
     if (!isempty (index))
       [name, inPar.copy] = shift (inPar.copy, index);
       if ( !feval (inPar.(method).(name).validator, value))
-        error("%sinvalid value for parameter '%s'", inPar.FunctionName, key);
+        error_invalid (inPar.FunctionName, key, inPar.(method).(name).validator);
       endif
       ## we use the name shifted from 'copy' instead of the key from 'args' in case
       ## the key is in the wrong case
@@ -301,11 +301,16 @@
   ## make sure that the given default value is actually valid
   ## TODO make sure that when using the default, it's only validated once
   if ( isa (val, 'function_handle') && !strcmpi (method, 'Required') && !feval (val, def) )
-    error ("default value does not validate with '%s'", func2str (val) );
+    error ("default value for '%s' failed validation with '%s'", name, func2str (val) );
   endif
 
 endfunction
 
+## this is just for consistency of error message
+function error_invalid (prefix, name, val)
+  error("%sargument '%s' failed validation %s", prefix, name, func2str (val));
+endfunction
+
 ################################################################################
 ## very auxiliary functions
 ################################################################################