1"""Module for errors thrown from ui_pages.""" 2 3from typing import List, Optional 4from xml.dom import minidom 5from blueberry.utils.ui_pages import ui_node 6 7 8class Error(Exception): 9 pass 10 11 12class ContextError(Error): 13 """Context related error.""" 14 15 def __init__(self, ctx, msg): 16 new_msg = f'{ctx.ad}: {msg}' 17 super().__init__(new_msg) 18 19 20class UIError(Error): 21 """UI page related error.""" 22 pass 23 24 25class UnknownPageError(Error): 26 """UI page error for unknown XML content. 27 28 Attributes: 29 ui_xml: Parsed XML object. 30 clickable_nodes: List of UINode with attribute `clickable="true"` 31 enabled_nodes: List of UINode with attribute `enabled="true"` 32 all_nodes: List of all UINode 33 """ 34 35 def __init__(self, 36 ui_xml: minidom.Document, 37 clickable_nodes: Optional[List[ui_node.UINode]] = None, 38 enabled_nodes: Optional[List[ui_node.UINode]] = None, 39 all_nodes: Optional[List[ui_node.UINode]] = None): 40 new_msg = f'Unknown ui_xml:\n{ui_xml.toxml()}\n' 41 self.ui_xml = ui_xml 42 self.enabled_nodes = enabled_nodes 43 self.clickable_nodes = clickable_nodes 44 self.all_nodes = all_nodes 45 super().__init__(new_msg) 46