tomerfiliba-org / reedsolomon

⏳🛡 Pythonic universal errors-and-erasures Reed-Solomon codec to protect your data from errors and bitrot. Includes a future-proof zero-dependencies pure-python implementation 🔮 and an optional speed-optimized Cython/C extension 🚀
http://pypi.python.org/pypi/reedsolo
Other
352 stars 86 forks source link

Problems with ReedSolomonError Exception handling #25

Open dchutchings opened 4 years ago

dchutchings commented 4 years ago

here's the relevant snippets of my code, which works fine with errors not exceeding RS capability

N, K = 255, 223
rsc = RSCodec(N-K, nsize=N)

for i in range(0,Npixels*N//K,N):
    try:
        rx_byte = np.append(rx_byte,np.uint8(rsc.decode(rx_enc[i:i+N])[0]))
    except ReedSolomonError:
        rx_byte = np.append(rx_byte,rx_enc[i:i+K])

I get

Traceback (most recent call last):

  File "  ", line 36, in <module>
    rx_byte = np.append(rx_byte,np.uint8(rsc.decode((rx_enc[i:i+N]))[0]))

  File "C:\ProgramData\Anaconda3\lib\site-packages\reedsolo.py", line 924, in decode
    rmes, recc, errata_pos = rs_correct_msg(chunk, nsym, fcr=self.fcr, generator=self.generator, erase_pos=e_pos, only_erasures=only_erasures)

  File "C:\ProgramData\Anaconda3\lib\site-packages\reedsolo.py", line 747, in rs_correct_msg
    err_pos = rs_find_errors(err_loc[::-1], len(msg_out), generator)

  File "C:\ProgramData\Anaconda3\lib\site-packages\reedsolo.py", line 693, in rs_find_errors
    raise ReedSolomonError("Too many (or few) errors found by Chien Search for the errata locator polynomial!")

ReedSolomonError: Too many (or few) errors found by Chien Search for the errata locator polynomial!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "  ", line 37, in <module>
    except ReedSolomonError:

NameError: name 'ReedSolomonError' is not defined
lrq3000 commented 4 years ago

Hello, thank you for reporting the 2 bugs.

It's a bit difficult for me to debug with this few information. Could you please write the corrupted message raising this error, and the original uncorrupted message?

lrq3000 commented 4 years ago

About your second error (ReedSolomonError is not defined), you first need to import the custom exception class with:

from reedsolo import ReedSolomonError

I have now added this info in the readme.