uwmadison-chm / bioread

Utilities to work with files from BIOPAC's AcqKnowlege software
MIT License
65 stars 21 forks source link

Some files do not load (fixed) #47

Open basgoncalves opened 2 weeks ago

basgoncalves commented 2 weeks ago

Hi there,

First of all thanks for the nice package. Super helpful. I don't know why but when trying to load certain files (who were completely ok when read in AcqKnowledge), I was ketting the error "Error reading file: read length must be non-negative or -1" from the reader.py (line 177).

TO fix this I just changed an exception and that work. See below:

Original code ''' class Reader(object): ... def _read_headers(self): ... 172 # In compressed files, markers come before compressed data. But

data_length is 0 for compressed files.

    self.marker_start_offset = (self.data_start_offset + self.data_length)
    self._read_markers()
    try:
        self._read_journal()
    except struct.error:
        logger.info("No journal information found.")

'''

Fixed code: ''' class Reader(object): ... def _read_headers(self): ... 172 # In compressed files, markers come before compressed data. But

data_length is 0 for compressed files.

    self.marker_start_offset = (self.data_start_offset + self.data_length)
    self._read_markers()
    try:
        try:
            self._read_journal()
        except struct.error:
            logger.info("No journal information found.")
    except Exception as e:
        logger.error("Error reading journal: %s" % e)

'''

hope this helps :) Bas

njvack commented 2 weeks ago

Huh! So the data comes across normally with the better exception handling?

basgoncalves commented 2 weeks ago

yes that is correct. At least from my recording.

njvack commented 2 weeks ago

Awesome; thanks!

Also! I don't know if this data is super confidential or anything, but if there's a way to post an affected file it would be neat to see if I can figure out what'd going on. If not... well, doing exception handling better here would help in other cases too, I think.