Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail gracefully when looking up a word that's not in the dictionary #18

Open
paulvonhippel opened this issue Jun 2, 2023 · 1 comment

Comments

@paulvonhippel
Copy link

pysle crashes when give a word that's not in its dictionary. It would be better, I think, to return a blank or something and continue running.

To give you an idea what I mean by "crash," I ran this code:

from pysle import isletool
isle = isletool.Isle()
print(isle.lookup('zit')[0]) # Get the first entry's pronunciation

and this is what I saw in the terminal:

Traceback (most recent call last):
  File "test_pysle.py", line 3, in <module>
    print(isle.lookup('zit')[0]) # Get the first entry's pronunciation
          ^^^^^^^^^^^^^^^^^^
  File "<path>\pysle\isletool.py", line 109, in lookup
    return self._lazyLoad(word)
           ^^^^^^^^^^^^^^^^^^^^
  File "<path>\pysle\isletool.py", line 62, in _lazyLoad
    raise errors.WordNotInIsleError(word)
pysle.utilities.errors.WordNotInIsleError: Word 'zit' not in ISLE dictionary.  Please add it to continue.
@timmahrt
Copy link
Owner

Sorry for the delay!

That's the intended behavior. I don't recall why I wrote it that way and if I were to write it again, maybe I wouldn't write it that way.

Does this cause any problems for you? If you need to prevent crashing you can do something like:

try:
    print(isle.lookup('zit')[0])
except errors.WordNotInIsleError:
    pass

Does that work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants