Home Assistant Unofficial Reference 2024.12.1
errors.py
Go to the documentation of this file.
1 """Blueprint errors."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Iterable
6 from typing import Any
7 
8 import voluptuous as vol
9 from voluptuous.humanize import humanize_error
10 
11 from homeassistant.exceptions import HomeAssistantError
12 
13 
15  """Base exception for blueprint errors."""
16 
17  def __init__(self, domain: str | None, msg: str) -> None:
18  """Initialize a blueprint exception."""
19  super().__init__(msg)
20  self.domaindomain = domain
21 
22 
24  """Base exception for blueprint errors."""
25 
26  def __init__(
27  self, domain: str | None, blueprint_name: str | None, msg: str
28  ) -> None:
29  """Initialize blueprint exception."""
30  super().__init__(domain, msg)
31  self.blueprint_nameblueprint_name = blueprint_name
32 
33 
35  """When we failed to load the blueprint."""
36 
37  def __init__(self, domain: str, blueprint_name: str, exc: Exception) -> None:
38  """Initialize blueprint exception."""
39  super().__init__(domain, blueprint_name, f"Failed to load blueprint: {exc}")
40 
41 
43  """When we encountered an invalid blueprint."""
44 
45  def __init__(
46  self,
47  domain: str | None,
48  blueprint_name: str | None,
49  blueprint_data: Any,
50  msg_or_exc: str | vol.Invalid,
51  ) -> None:
52  """Initialize an invalid blueprint error."""
53  if isinstance(msg_or_exc, vol.Invalid):
54  msg_or_exc = humanize_error(blueprint_data, msg_or_exc)
55 
56  super().__init__(
57  domain,
58  blueprint_name,
59  f"Invalid blueprint: {msg_or_exc}",
60  )
61  self.blueprint_datablueprint_data = blueprint_data
62 
63 
65  """When we encountered invalid blueprint inputs."""
66 
67  def __init__(self, domain: str, msg: str) -> None:
68  """Initialize an invalid blueprint inputs error."""
69  super().__init__(
70  domain,
71  f"Invalid blueprint inputs: {msg}",
72  )
73 
74 
76  """When we miss an input."""
77 
78  def __init__(
79  self, domain: str, blueprint_name: str, input_names: Iterable[str]
80  ) -> None:
81  """Initialize blueprint exception."""
82  super().__init__(
83  domain,
84  blueprint_name,
85  f"Missing input {', '.join(sorted(input_names))}",
86  )
87 
88 
90  """Error when file already exists."""
91 
92  def __init__(self, domain: str, blueprint_name: str) -> None:
93  """Initialize blueprint exception."""
94  super().__init__(domain, blueprint_name, "Blueprint already exists")
95 
96 
98  """Error when a blueprint is in use."""
99 
100  def __init__(self, domain: str, blueprint_name: str) -> None:
101  """Initialize blueprint exception."""
102  super().__init__(domain, blueprint_name, "Blueprint in use")
None __init__(self, str|None domain, str msg)
Definition: errors.py:17
None __init__(self, str domain, str blueprint_name)
Definition: errors.py:100
None __init__(self, str|None domain, str|None blueprint_name, str msg)
Definition: errors.py:28
None __init__(self, str domain, str blueprint_name, Exception exc)
Definition: errors.py:37
None __init__(self, str domain, str blueprint_name)
Definition: errors.py:92
None __init__(self, str|None domain, str|None blueprint_name, Any blueprint_data, str|vol.Invalid msg_or_exc)
Definition: errors.py:51
None __init__(self, str domain, str blueprint_name, Iterable[str] input_names)
Definition: errors.py:80
str humanize_error(HomeAssistant hass, vol.Invalid validation_error, str domain, dict config, str|None link, int max_sub_error_length=MAX_VALIDATION_ERROR_ITEM_LENGTH)
Definition: config.py:520