Coverage for /home/kale/kxgames/libraries/kxg/kxg/errors.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python3 # pylint: disable=unused-import
## Anatomy of an error message # ============================ # 1. One line that succinctly states what the problem is. Be mindful that # errors can be raised in situations you might not have thought of, so try # to phrase this line in a way that doesn't make assumptions and that won't # mislead the user if it's triggered in an unexpected way. # # 2. In a separate paragraph, a few sentences that elaborate on the problem. # In particular, try to cover the following points: # # - Explain the most likely cause of the problem. This is in slight contrast # to the first line, which should strive to be context-neutral. # # - Explain why this is a problem, or in other words, why the engine had to # raise an exception when it encountered this scenario. # # - Suggest a way to solve the problem.
## Anatomy of an assertion message # ================================ # 1. One sentence explaining why this line should never have been reached. # # "SomeClass.some_method() should've refused to ..."
## ApiUsageError vs assertions # ============================ # Use ApiUsageError for errors that the user trigger by misusing the game # engine's public API. # # Use assertions for errors the user should not be able to trigger without # changing private attributes or calling private methods. # # For example, there are several places where the game engine could notice that # the same token is being added to the world twice. It's good for all these # places to make the check to be sure they're being used correctly and that a # token can't be added to the world twice, but only the first one should raise # an ApiUsageError. The rest should be assertions, and should mention what was # supposed to have happened.
# Lowercase the first letter of the error message, to enforce the # recommended style. Note that this won't have any effect if the message # starts with a template argument (e.g. {}), which is actually intentional. # Template arguments are often identifier names, and we don't want to # change those.
# Make sure the summary doesn't overflow its allocated space even after # python adds the 'kxg.errors.ApiUsageError: ' prefix.
paragraphs.pop(0).replace('\n', ''), width=ApiUsageError.message_width, initial_indent=' ' * len(prefix), ).strip()
# If a details paragraph was given, wrap it to fit within the allocated # space. Take care to preserve the indentation of each paragraph, # which may be organizing lists and things like that.
paragraph.replace('\n', ''), width=ApiUsageError.message_width, initial_indent=initial_indent, subsequent_indent=subsequent_indent, )
def format_assertion_message(message): return format_error_message('AssertionError: ', 3, message)
msg = format_assertion_message
""" Tell the user when they're misusing the game engine and suggest how they should be using it instead. """
if __debug__: else: return lambda *args, **kwargs: None
def require_instance(prototype, object):
expected {prototype_cls}, but got {object_cls} instead.""")
forgot to call the {prototype_cls} constructor in {object_cls}.__init__().
The game engine was passed an object that inherits from {prototype_cls} but is missing the '{member_name}' attribute. This usually means that you forgot to call the {prototype_cls} constructor in your subclass.""")
|