Skip to content

make fims::Vector out of bounds error more informative #1412

Description

@Andrea-Havron-NOAA

Currently when there is an out of bounds error on a fims::Vector, the following error is returned:

fims::Vector out of bounds

We can improve the information of this error message by adding the name of the vector and including index and size information in the error.

To Do Items:

  • Add variable_name_m to fims::Vector class (file)
  • Create a set_variable_name method in fims::Vector class to set the name
  • Set fims::Vector names in rcpp_objects/rcpp_* files. (See example below)
  • Enhance error message in inline Type &operator[](size_t pos) and inline const Type &operator[](size_t n) to include the name of the fims::Vector, the total size of the vector, and the index (subtract 1 to convert to R) throwing the error.

Example setting fims::Vector name:

for (size_t i = 0; i < this->slope.size(); i++) {
      selectivity->slope[i] = this->slope[i].initial_value_m;
      if (this->slope[i].estimation_type_m.get() == "fixed_effects") {
        ss.str("");
        ss << "Selectivity." << this->id << ".slope." << this->slope[i].id_m;
        info->RegisterParameterName(ss.str());
        info->RegisterParameter(selectivity->slope[i]);
      }
      if (this->slope[i].estimation_type_m.get() == "random_effects") {
        ss.str("");
        ss << "Selectivity." << this->id << ".slope." << this->slope[i].id_m;
        info->RegisterRandomEffectName(ss.str());
        info->RegisterRandomEffect(selectivity->slope[i]);
      }
    }

The above original code can be modified to:

ss.str("");
ss << "Selectivity." << this->id << ".slope
selectivity->slope.set_variable_name(ss.str());
for (size_t i = 0; i < this->slope.size(); i++) {
      selectivity->slope[i] = this->slope[i].initial_value_m;
      ss  << "." << this->slope[i].id_m;
      if (this->slope[i].estimation_type_m.get() == "fixed_effects") {
        info->RegisterParameterName(ss.str());
        info->RegisterParameter(selectivity->slope[i]);
      }
      if (this->slope[i].estimation_type_m.get() == "random_effects") {
        info->RegisterRandomEffectName(ss.str());
        info->RegisterRandomEffect(selectivity->slope[i]);
      }
    }

Metadata

Metadata

Labels

status: triage_neededThis is not approved for this milestone, do not work on it yet

Type

No type

Fields

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions