qubes-exc.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. :py:mod:`qubes.exc` -- Exceptions
  2. =================================
  3. As most of the modern programming languages, Python has exceptions, which can be
  4. thrown (``raise``\ d) when something goes bad. What exactly means "bad" depends
  5. on several circumstances.
  6. One of those circumstances is who exactly is to blame: programmer or user? Some
  7. errors are commited by programmer and will most probably result it program
  8. failure. But most errors are caused by the user, notably by specifying invalid
  9. commands or data input. Those errors *should not* result in failure, but fault
  10. and be handled gracefuly. One more time, what "gracefuly" means depends on
  11. specific program and its interface (for example GUI programs should most likely
  12. display some admonition, but will not crash).
  13. In Qubes we have special exception class, :py:class:`qubes.exc.QubesException`,
  14. which is dedicated to handling user-caused problems. Programmer errors should
  15. not result in raising QubesException, but it should instead result in one of the
  16. standard Python exception. QubesExceptions should have a nice message that can
  17. be shown to the user. On the other hand, some children classes of QubesException
  18. also inherit from children of :py:class:`StandardException` to allow uniform
  19. ``except`` clauses.
  20. Often the error relates to some domain, because we expect it to be in certain
  21. state, but it is not. For example to start a machine, it should be halted. For
  22. that we have the children of the :py:class:`qubes.exc.QubesVMError` class. They
  23. all take the domain in question as their first argument and an (optional)
  24. message as the second. If not specified, there is stock message which is
  25. generally informative enough.
  26. On writing error messages
  27. -------------------------
  28. As a general rule, error messages should be short but precise. They should not
  29. blame user for error, but the user should know, what had been done wrong and
  30. what to do next.
  31. If possible, write the message that is stating the fact, for example "Domain is
  32. not running" instead of "You forgot to start the domain" (you fool!). Avoid
  33. commanding user, like "Start the domain first" (user is not a function you can
  34. call for effect). Instead consider writing in negative form, implying expected
  35. state: "Domain is not running" instead of "Domain is paused" (yeah, what's wrong
  36. with that?).
  37. Also avoid implying the personhood of the computer, including adressing user in
  38. second person. For example, write "Sending message failed" instead of "I failed
  39. to send the message".
  40. Inheritance diagram
  41. -------------------
  42. .. inheritance-diagram:: qubes.exc
  43. Module contents
  44. ---------------
  45. .. automodule:: qubes.exc
  46. :members:
  47. :show-inheritance:
  48. .. vim: ts=3 sw=3 et tw=80