Pyvista: Better error types

Created on 14 Apr 2020  路  4Comments  路  Source: pyvista/pyvista

We should overhaul all places and error is raised in the API. AssertionError, Exception, and RuntimeError are overused (and inappropriately used):

  • AssertionError is raised 47 times
  • Exception is raised 49 times
  • RuntimeError is raised 56 times

ref https://github.com/pyvista/pyvista/pull/685#pullrequestreview-393235207

enhancement 馃崗 low-hanging-fruit

Most helpful comment

I forgot about AssertionError and RuntimeErrors, I'll close this and open a PR for the others.

All 4 comments

Quick reference for when to raise the common exceptions, which I think are conventional.

TypeError - When the value is of wrong type, or None if that's not expected.

ValueError - When the value is of the correct type, but wrong value.

AssertionError - Assert should really only be used in testing 99.9% of the time.

RuntimeError - Encountered an error which can not be recovered from.

IOError - Should be rarely used, maybe for a corrupt file.

FileNotFoundError - Self explanatory.

Exception - Almost never, should keep an eye out for this or bare except in try-excepts too.

Thanks for that list @JevinJ! It will be helpful to follow those guidelines when fixing this issue

@JevinJ please close this if you think we've solved this issue.

I forgot about AssertionError and RuntimeErrors, I'll close this and open a PR for the others.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

banesullivan picture banesullivan  路  6Comments

GuillaumeFavelier picture GuillaumeFavelier  路  5Comments

wangfudong picture wangfudong  路  3Comments

banesullivan picture banesullivan  路  3Comments

dennissergeev picture dennissergeev  路  5Comments