Action #3474

Explicit error message in GModelSpectralFunc constructor from xml for file attribute absent or empty file

Added by Tibaldo Luigi over 3 years ago. Updated about 2 years ago.

Status:ClosedStart date:12/02/2020
Priority:NormalDue date:
Assigned To:Knödlseder Jürgen% Done:

100%

Category:-
Target version:2.0.0
Duration:

Description

Currently when a GModelSpectralFunc is built from an XML file there is no explicit error message thrown by GModelSpectralFunc::read if there is no file attribute, or by GModelSpectralFunc::load_nodes if the file exists but it is empty. In both cases the model is initialised with empty energy node and value vectors. This results in errors when the model is used later, but the error message thrown then is not very easy to trace back to its root cause.
I think it could be useful to add error messages covering these two cases more transparent for the user.


Recurrence

No recurrence.

History

#1 Updated by Knödlseder Jürgen about 2 years ago

  • Status changed from New to In Progress
  • Assigned To set to Knödlseder Jürgen
  • % Done changed from 0 to 10

I confirm the first case (no file attribute), yet if an empty file function file is specified the following error occurs:

>>> import gammalib
>>> m=gammalib.GModels('nofile.xml')
>>> m=gammalib.GModels('emptyfile.xml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/gamma/lib/python2.7/site-packages/gammalib/model.py", line 402, in __init__
    _model.GModels_swiginit(self, _model.new_GModels(*args))
ValueError: *** ERROR in GModelSpectralFunc::load_nodes(GFilename&): Invalid value. File function ASCII file "empty_filefunction.txt" contains 0 rows but at least 2 rows are required. Please specify a file function ASCII file with at least two rows.

#2 Updated by Knödlseder Jürgen about 2 years ago

  • Status changed from In Progress to Pull request
  • % Done changed from 10 to 90

I modified the code so that a missing attribute will also lead to an error:

>>> import gammalib
>>> m=gammalib.GModels('nofile.xml')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/gamma/lib/python2.7/site-packages/gammalib/model.py", line 402, in __init__
    _model.GModels_swiginit(self, _model.new_GModels(*args))
ValueError: *** ERROR in GModelSpectralFunc::load_nodes(GFilename&): Invalid argument. Empty file function ASCII file name specified. Please specify a valid file function ASCII file name.

#3 Updated by Knödlseder Jürgen about 2 years ago

  • Status changed from Pull request to Closed
  • % Done changed from 90 to 100

Merged into devel.

Also available in: Atom PDF