bugGNU Octave - Bugs: bug #63908, load: No error when asking for a...


bug #63908: load: No error when asking for a non existing variable

Submitter:  None
Submitted:  Fri 10 Mar 2023 02:09:06 PM UTC
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * 7.3.0
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Fri 10 Mar 2023 11:23:59 PM UTC, comment #2: 

WIP fix:

diff -r 16b233ccaeab libinterp/corefcn/load-save.cc
--- a/libinterp/corefcn/load-save.cc    Wed Mar 08 18:09:14 2023 -0800
+++ b/libinterp/corefcn/load-save.cc    Fri Mar 10 18:19:24 2023 -0500
@@ -440,7 +440,9 @@ load_save_system::load_vars (std::istrea

-      if (stream.eof () || name.empty ())
+      if (name.empty ())  // FIXME: need to refine this
+        error ("load: specified variable(s) not found in file");
+      else if (stream.eof ())

This causes an error for the cases where non-existent variables are requested from a file.

The error needs to be suppressed for the cases where the variable does exist and is successfully loaded. Is there a reliable way to tell the cases apart so that an empty name means it's not found?

Arun Giridhar <arungiridhar>
Group Member
Fri 10 Mar 2023 03:59:55 PM UTC, comment #1: 

Thanks for your report, I can confirm the issue for all but the "-text" format. Here is a self contained script to reproduce:

fmt = {"-ascii", "-text", "-binary", "-hdf5", "-4", "-6", "-7"};

toto = 10;
for ii = 1:numel (fmt)
  save (fmt{ii}, "toto.mat", "toto")
    load toto.mat titi
    printf ("Load silently loads nothing for format %s\n", fmt{ii})
    printf ("Ok for format %s\n", fmt{ii})

Pantxo Diribarne <pantxo>
Group Member
Fri 10 Mar 2023 02:09:06 PM UTC, original submission:  

datasetname is variable

file1.mat and file2.mat are files storing data sets.

>> load file1.mat datasetname
>> datasetname
datasetname = DS1

>> load file2.mat datasetname
>> datasetname
datasetname = DS1

The problem was file2.mat had no variable datasetname, load command gave no error, and old value of datasetname was used, causing error.

Load should givee error for variable name not found.



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

Attach Files:

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 arungiridhar (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-03-10 pantxo CategoryNone Octave Function
        Item GroupNone Missed Error or Warning
        StatusNone Confirmed
        Summaryload variable no error load: No error when asking for a non existing variable

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code