bugGNU Octave - Bugs: bug #63556, error() function shows traceback...

 
 

bug #63556: error() function shows traceback messages when error message end with newline in special cases

Submitter:  José Luis García Pallero <jgpallero>
Submitted:  Wed 21 Dec 2022 05:47:50 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Documentation
Status:  Fixed Assigned to:  None
Originator Name:  jgpallero Open/Closed:  * Closed
Release:  * 7.3.0 Operating System:  * Any
Fixed Release:  8.1.0 Planned Release:  8.1.0
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 23 Dec 2022 04:40:53 AM UTC, comment #6: 

Confirming, Octave needs to stay Matlab-compatible and Matlab also does not interpret escape characters such as '\n' when there is only a single string.

For example, in Matlab


error ('abc\ndef\nghi\n')
abc\ndef\nghi\n


while in Octave the string "error: " is prepended


error ('abc\ndef\nghi\n')
error: abc\ndef\nghi\n


Marking bug as fixed (with Markus's change to the documentatino) and closing report.

Rik <rik5>
Group administrator
Wed 21 Dec 2022 07:18:54 PM UTC, comment #5: 

I pushed an update to the documentation here:
https://hg.savannah.gnu.org/hgweb/octave/rev/96d321d59ee3

Marking as ready for test.

Markus Mützel <mmuetzel>
Group administrator
Wed 21 Dec 2022 06:56:38 PM UTC, comment #4: 


comentario nº3:

> The following works in Matlab and in Octave if there are no additional arguments after the format string and the error should contain newline characters:


> error (sprintf ('Error with newline\n'));


Thanks!

José Luis García Pallero <jgpallero>
Wed 21 Dec 2022 06:52:55 PM UTC, comment #3: 

The following works in Matlab and in Octave if there are no additional arguments after the format string and the error should contain newline characters:

error (sprintf ('Error with newline\n'));


Markus Mützel <mmuetzel>
Group administrator
Wed 21 Dec 2022 06:50:25 PM UTC, comment #2: 

Single-quoted strings behave the same in Octave and in Matlab.
Double-quoted strings used to be Octave-specific and differ from single-quoted strings in that escape sequences (like "\n") are evaluated (like `fprintf` does). E.g., compare the result of `numel('\n')` with `numel("\n")` in Octave.
(Unrelated to this issue: Double-quotes now create string objects in Matlab. Those are incompatible to Octave's double-quoted strings.)

The error function works like `fprintf` only if there are additional arguments after the template. That means the examples that use one single single-quoted input argument don't end with a newline character. But they end with "n". Hence, the traceback is included in the displayed error message.

The documentation could probably be improved to better point that out.


Markus Mützel <mmuetzel>
Group administrator
Wed 21 Dec 2022 05:54:33 PM UTC, comment #1: 

In Octave the error() works as expected if the case

error('Incorrect number of input parameters\n');

is written with double quoted string:

error("Incorrect number of input parameters\n");

but this is incompatible with Matlab (at least with version 9.2.0.538062 (R2017a)):

Error using error
The message must be specified as either a character vector or a message structure.


José Luis García Pallero <jgpallero>
Wed 21 Dec 2022 05:47:50 PM UTC, original submission:  

According to Octave documentation, in the error() function

If the error message ends in a newline character, Octave will print
the message but will not display any traceback messages as it
returns control to the top level


See this first exmple

function [b] = test1(a)

b = subfunction(a);

function [b] = subfunction(a)

if nargin<2
    error('Incorrect number (%d) of input parameters \n',nargin);
end

and now this

function [b] = test2(a)

b = subfunction(a);

function [b] = subfunction(a)

if nargin<2
    error('Incorrect number of input parameters\n');
end


I obtain this results:

>> test1(8)
error: Incorrect number of input parameters (1)
>> test2(8)
error: Incorrect number of input parameters\n
error: called from
    test2>subfunction at line 8 column 5
    test2 at line 3 column 3


Only the first example works as expected, i.e., not printing the error traceback as the error message end with the '\n' character. The only difference in the error() calls is that in the first case information is passed through %d. Is this a bug in error()?

Also, if I insert some '\n' in the middle of the error message, it is only interpreted if information were passed to the message, i.e., something as

error('Incorrect number (%d) of\ninput parameters \n',nargin);

will produce the message

error: Incorrect number (1) of
input parameters

but if I write

error('Incorrect number of\ninput parameters \n');

the result is

error: Incorrect number of\ninput parameters\n
error: called from
    test2>subfunction at line 8 column 5
    test2 at line 3 column 3


José Luis García Pallero <jgpallero>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by jgpallero (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
    2022-12-23 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2022-12-21 mmuetzel StatusConfirmed Ready For Test
        Fixed ReleaseNone 8.1.0
    2022-12-21 mmuetzel Item GroupInaccurate Result Documentation
        StatusNone Confirmed
        Planned ReleaseNone 8.1.0

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code