bugGNU Octave - Bugs: bug #66873, inputParser does not print the...

 
 

bug #66873: inputParser does not print the original error message

Submitter:  Avinoam Kalma <avinoam>
Submitted:  Wed 05 Mar 2025 05:45:47 AM UTC
   
 
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Other
Status:  Fixed Assigned to:  None
Originator Name:  Avinoam Open/Closed:  * Closed
Release:  * 9.3.0 Release: 
Operating System:  * Any Fixed Release:  11.1.0 (current default)
Planned Release:  11.1.0 (current default)
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 23 Mar 2025 04:38:52 PM UTC, comment #4: 

Checked in changeset on development branch.  Marking bug as Fixed and closing report.

Rik <rik5>
Group administrator
Thu 06 Mar 2025 07:58:58 PM UTC, comment #3: 

Thanks @Rik,
this changeset works well for me.

Avinoam Kalma <avinoam>
Group Member
Thu 06 Mar 2025 01:58:03 AM UTC, comment #2: 

One more thought, it might be better to still list the parameter that is failing validation.  Conceptually easy, but the reporting string gets a bit messy.  I did a quick code test and the message is


error: foo: failed validation of 'type'.  type_check: 'clint' (variable type) does not match any of
'good', 'bad', 'ugly'


I guess Octave could check for a leading "name:" and strip that from the error message which it rethrows.

Rik <rik5>
Group administrator
Thu 06 Mar 2025 01:45:25 AM UTC, comment #1: 

Try the attached changeset (made against default branch).  If it works for you I will commit it.

(file #56977)

Rik <rik5>
Group administrator
Wed 05 Mar 2025 05:45:47 AM UTC, original submission:  

I am using a validation function for input parsing.

For example:

function validate_type(x)
  validatestring(x, {'good', 'bad', 'ugly'}, 'type_check', 'type');
endfunction


using this function:

>> validate_type('clint')
error: type_check: 'clint' (variable type) does not match any of
'good', 'bad', 'ugly'
error: called from
    validatestring at line 125 column 5
    validate_type at line 2 column 3


Using it with inputParser:


function foo(varargin)

% Create input parser object
p = inputParser;
p.CaseSensitive = false;
p.FunctionName = 'foo';

% Add optional parameters with validation functions
addParameter(p, 'type', 'good', @validate_type);
% Parse inputs
parse(p, varargin{:});

endfunction


and running the code:

>> foo('type', 'clint')
error: foo: failed validation of 'type'.  Checked with "validate_type"
error: called from
    error at line 693 column 7
    validate_arg at line 599 column 11
    parse at line 517 column 11
    foo at line 11 column 1


The inputParser does not print the original error message, and the message is less informative
(it does not print the exact reason for the failure).

Any fix or workaround?
Thanks.

Avinoam Kalma <avinoam>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #56977:  bug66873.cset added by rik5 (2KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by avinoam (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-03-23 rik5 StatusPatch Reviewed Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 11.1.0 (current default)
    2025-03-06 avinoam StatusPatch Submitted Patch Reviewed
    2025-03-06 rik5 Attached File- Added bug66873.cset, #56977
        StatusNone Patch Submitted
        Planned ReleaseNone 11.1.0 (current default)

    Back to the top

    Powered by Savane 3.14-7003.
    Corresponding source code