NeurodataWithoutBorders / matnwb

A Matlab interface for reading and writing NWB files
BSD 2-Clause "Simplified" License
48 stars 32 forks source link

Improve warning for types.util.checkUnset #592

Closed ehennestad closed 2 months ago

ehennestad commented 2 months ago

The warning which is raised in types.util.checkUnset could be improved and should be different depending on context:

1) When creating types with properties that are not part of the schema:

types.hdmf_common.VectorIndex('test', 1)
Warning: Unexpected properties {test}.

Your schema version may be incompatible with the file.  Consider checking the schema version of the file with
`util.getSchemaVersion(filename)` and comparing with the YAML namespace version present in nwb-schema/core/nwb.namespace.yaml 
> In types.util.checkUnset (line 18)
In types.hdmf_common.VectorIndex (line 27) 

ans = 

  VectorIndex with properties:

         target: []
    description: ''
           data: []

In this case the issue is not related to the schema version so this warning message is misleading.

2) When reading a file:

>> nwbRead('~/sub-mouse-INETJ_ses-20200407-sample-10_slice-20200407-slice-1_cell-20200407-sample-10_icephys.nwb')
Warning: Unexpected properties {description}.

Your schema version may be incompatible with the file.  Consider checking the schema version of the file with
`util.getSchemaVersion(filename)` and comparing with the YAML namespace version present in nwb-schema/core/nwb.namespace.yaml 
> In types.util.checkUnset (line 18)
In types.hdmf_common.VectorIndex (line 23)
In io.parseDataset (line 81)
In io.parseGroup (line 22)
In io.parseGroup (line 38)
In io.parseGroup (line 38)
In io.parseGroup (line 38)
In nwbRead (line 79) 

This warning message very little information about which dataset the read operation failed and is difficult to debug.

Suggestion: Make warning message that:

  1. Clearly states which data type the mentioned property does not belong to.
  2. When reading, state which location in the file the warning is relevant for.
  3. Only mention schema version if file is being read