roboglia.utils.check_key

check_key(key, dict_info, context, context_id, logger, message=None)[source]

Checks if a key is in a dictionary dict_info and raises a customized exception message with better context.

Parameters
  • key (str) – the key we are looking for

  • dict_info (dict) – the dictionary where we are looking

  • context (str) – a string indicating the context of the check, for example ‘Bus’ or ‘Device’

  • context_id (str or int) – indicates the precise context (the name of the object or, in case the key we are searching is the name we will have to use the index of the item in the initialization dictionary)

  • logger (logger object) – where the logging will be written

  • message (str) – if this is provided the function will use this message for logging and raise instead of building a message specific for the context.

Raises

KeyError – if the key is not found in the dict_info