Plot Reference to Missing SubSection Crashes GUI
Edit: It actually turns out to be even more general and any plot reference to a SubSection which has not been instantiated yet will cause the GUI to crash. For example, uploading the following yaml schema and then creating a MyTopSection
in the GUI will cause a crash as the SubSection MySubSection
has yet to be instantiated:
definitions:
sections:
MySubSection:
quantities:
x:
type: np.float64
shape: ['*']
y:
type: np.float64
shape: ['*']
MyTopSection:
m_annotations:
eln:
plot:
- x: my_sub_section/x
y: my_sub_section/y
sub_sections:
my_sub_section:
section: '#/MySubSection'
Below you find a more detailed example of the specific case where a repeating SubSection has yet to be defined:
If a plot reference to a schema refers to a repeating SubSection which is not defined in the data file the GUI will crash with the error:
resolveInternalRefSingle
src/utils.js:1248
1245 | const segments = path.split('/').filter(segment => segment !== '')
1246 | let current = data
1247 | for (const segment of segments) {
> 1248 | if (!current) throw new Error(`Path does not exist: ${path}`)
| ^ 1249 | if (isNaN(segment)) {
1250 | current = current[segment] || current._properties?.[segment] || current.sub_section?._properties?.[segment]
1251 | } else {
Here is a minimum breaking example in yaml:
definitions:
sections:
MySubSection:
quantities:
x:
type: np.float64
shape: ['*']
y:
type: np.float64
shape: ['*']
MyTopSection:
m_annotations:
eln:
plot:
- x:
- my_sub_sections/0/x
- my_sub_sections/1/x
- my_sub_sections/2/x
y:
- my_sub_sections/0/y
- my_sub_sections/1/y
- my_sub_sections/2/y
sub_sections:
my_sub_sections:
repeats: True
section: '#/MySubSection'
data:
m_def: '#/MyTopSection'
my_sub_sections:
- x: [0,1]
y: [1,2]
- x: [0,0.5]
y: [1,2]
I see three different ways that this could be solved:
- Somehow catch the error and display it without crashing the GUI
- Ignore paths that cannot be found
- Allow users to reference repeating SubSections with a range, i.e. something like:
x: my_sub_sections/:/x
. This is very similar to the feature request in #1313 (closed).
I personally think that the 3rd option would be very convenient but if that is technically hard to implement I would at least suggest the 2nd option (which would be needed as part of the 3rd option anyways).