ha-supervisor/supervisor/exceptions.py

592 lines
11 KiB
Python
Raw Normal View History

2018-04-21 22:33:06 +02:00
"""Core Exceptions."""
from collections.abc import Callable
2018-04-21 22:33:06 +02:00
class HassioError(Exception):
"""Root exception."""
def __init__(
self,
message: str | None = None,
logger: Callable[..., None] | None = None,
) -> None:
"""Raise & log."""
if logger is not None and message is not None:
logger(message)
# Init Base
if message is not None:
super().__init__(message)
else:
super().__init__()
2018-04-21 22:33:06 +02:00
class HassioNotSupportedError(HassioError):
"""Function is not supported."""
2018-04-22 09:59:43 +02:00
# JobManager
class JobException(HassioError):
"""Base job exception."""
class JobConditionException(JobException):
"""Exception happening for job conditions."""
# HomeAssistant
class HomeAssistantError(HassioError):
"""Home Assistant exception."""
class HomeAssistantUpdateError(HomeAssistantError):
"""Error on update of a Home Assistant."""
class HomeAssistantCrashError(HomeAssistantError):
"""Error on crash of a Home Assistant startup."""
class HomeAssistantAPIError(HomeAssistantError):
"""Home Assistant API exception."""
class HomeAssistantAuthError(HomeAssistantAPIError):
"""Home Assistant Auth API exception."""
class HomeAssistantWSError(HomeAssistantAPIError):
"""Home Assistant websocket error."""
class HomeAssistantWSNotSupported(HomeAssistantWSError):
"""Raise when WebSockets are not supported."""
2021-11-29 17:21:09 +01:00
class HomeAssistantWSConnectionError(HomeAssistantWSError):
"""Raise when the WebSocket connection has an error."""
class HomeAssistantJobError(HomeAssistantError, JobException):
"""Raise on Home Assistant job error."""
# Supervisor
class SupervisorError(HassioError):
"""Supervisor error."""
class SupervisorUpdateError(SupervisorError):
"""Supervisor update error."""
class SupervisorAppArmorError(SupervisorError):
"""Supervisor AppArmor error."""
class SupervisorJobError(SupervisorError, JobException):
"""Raise on job errors."""
# HassOS
class HassOSError(HassioError):
"""HassOS exception."""
class HassOSUpdateError(HassOSError):
"""Error on update of a HassOS."""
class HassOSJobError(HassOSError, JobException):
"""Function not supported by HassOS."""
class HassOSDataDiskError(HassOSError):
"""Issues with the DataDisk feature from HAOS."""
# All Plugins
class PluginError(HassioError):
"""Plugin error."""
class PluginJobError(PluginError, JobException):
"""Raise on job error with plugin."""
# HaCli
class CliError(PluginError):
"""HA cli exception."""
class CliUpdateError(CliError):
"""Error on update of a HA cli."""
class CliJobError(CliError, PluginJobError):
"""Raise on job error with cli plugin."""
# Observer
class ObserverError(PluginError):
"""General Observer exception."""
class ObserverUpdateError(ObserverError):
"""Error on update of a Observer."""
class ObserverJobError(ObserverError, PluginJobError):
"""Raise on job error with observer plugin."""
# Multicast
class MulticastError(PluginError):
"""Multicast exception."""
class MulticastUpdateError(MulticastError):
"""Error on update of a multicast."""
class MulticastJobError(MulticastError, PluginJobError):
"""Raise on job error with multicast plugin."""
# DNS
class CoreDNSError(PluginError):
"""CoreDNS exception."""
class CoreDNSUpdateError(CoreDNSError):
"""Error on update of a CoreDNS."""
class CoreDNSJobError(CoreDNSError, PluginJobError):
"""Raise on job error with dns plugin."""
# Audio
class AudioError(PluginError):
"""PulseAudio exception."""
class AudioUpdateError(AudioError):
"""Error on update of a Audio."""
class AudioJobError(AudioError, PluginJobError):
"""Raise on job error with audio plugin."""
# Addons
class AddonsError(HassioError):
"""Addons exception."""
class AddonConfigurationError(AddonsError):
"""Error with add-on configuration."""
class AddonsNotSupportedError(HassioNotSupportedError):
"""Addons don't support a function."""
class AddonsJobError(AddonsError, JobException):
"""Raise on job errors."""
# Arch
class HassioArchNotFound(HassioNotSupportedError):
"""No matches with exists arch."""
# Updater
class UpdaterError(HassioError):
"""Error on Updater."""
class UpdaterJobError(UpdaterError, JobException):
"""Raise on job error."""
# Auth
class AuthError(HassioError):
"""Auth errors."""
class AuthPasswordResetError(HassioError):
"""Auth error if password reset failed."""
2018-04-23 21:10:48 +02:00
# Host
2018-04-23 21:10:48 +02:00
class HostError(HassioError):
"""Internal Host error."""
class HostNotSupportedError(HassioNotSupportedError):
"""Host function is not supprted."""
class HostServiceError(HostError):
"""Host service functions failed."""
class HostAppArmorError(HostError):
"""Host apparmor functions failed."""
Network: abstract dbus and supervisor - ipv6/wifi/vlan (#2217) * Abstract code between dbus - supervisor * cleanup v2 * fix address vs interface * fix API calls * Fix methodnames * add vlan type * add vlan support * Fix tests * Add wifi support * more OOO * fix typing import * typing part 2 * Fix profile * fix test payload * ignore powersafe * support privancy * fix property * Fix tests * full support all API * Fix all * more robust * Update supervisor/dbus/network/connection.py Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * Fix gateway * fix empty gateway * Allow no ipv6 or ipv4 kernel support * Exclude device drivers * Add wifi * Use loop on api * refactory p1 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p2 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p3 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p4 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p5 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p6 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p7 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * refactory p8 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * Fix lint * update sup p1 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * update sup p2 Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * fix tests Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * fix logging Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * improve mock handling Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * add fixtures Signed-off-by: Pascal Vizeli <pvizeli@syshack.ch> * fix tests * better testing * Add more tests * Fix API test * Add test for vlan payload * Support variation * Fix doc string * support remove & wifi scan * make sure we ignore local-link on ipv6 * remove privancy - add vlan * Fix tests * fix isort * Fixture dbus by commands * Add dnsmanager fixture * expose commands called by dbus * Add wifi tests * Update supervisor/plugins/dns.py Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * Address comments & fix tests * change url to be closer on others Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
2020-11-09 08:56:42 +01:00
class HostNetworkError(HostError):
"""Error with host network."""
class HostNetworkNotFound(HostError):
"""Return if host interface is not found."""
Add enhanced logging REST endpoints using systemd-journal-gatewayd (#3291) * Add enhanced logging REST endpoints using systemd-journal-gatewayd Add /host/logs/entries and /host/logs/{identifier}/entries to expose log entries from systemd-journald running on the host. Use systemd-journal-gatewayd which exposes the logs to the Supervisor via Unix socket. Current two query string parameters are allowed: "boot" and "follow". The first will only return logs since last boot. The second will keep the HTTP request open and send new log entries as they get added to the systemd-journal. * Allow Range header Forward the Range header to systemd-journal-gatewayd. This allows to select only a certain amount of log data. The Range header is a standard header to select only partial amount of data. However, the "entries=" prefix is custom for systemd-journal-gatewayd, denoting that the numbers following represent log entries (as opposed to bytes or other metrics). * Avoid connecting if systemd-journal-gatewayd is not available * Use path for all options * Add pytests * Address pylint issues * Boot ID offsets and slug to identifier * Fix tests * API refactor from feedback * fix tests and add identifiers * stop isort and pylint fighting * fix tests * Update default log identifiers * Only modify /host/logs endpoints * Fix bad import * Load log caches asynchronously at startup * Allow task to complete in fixture * Boot IDs and identifiers loaded on demand * Add suggested identifiers * Fix tests around boot ids Co-authored-by: Mike Degatano <michael.degatano@gmail.com>
2022-10-13 17:40:11 +02:00
class HostLogError(HostError):
"""Internal error with host log."""
# API
class APIError(HassioError, RuntimeError):
"""API errors."""
class APIForbidden(APIError):
"""API forbidden error."""
class APIAddonNotInstalled(APIError):
"""Not installed addon requested at addons API."""
# Service / Discovery
class DiscoveryError(HassioError):
"""Discovery Errors."""
class ServicesError(HassioError):
"""Services Errors."""
Use Python dbus-next D-Bus library (#3234) * Use the correct interface name to get properties of systemd It seems that gdbus (or systemd) automatically pick the correct interface and return the properties. However, dbussy requires the correct interface name to get all properties. * Don't expect array from Strength property The property returns a type "y" which equates to "guchar": https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.AccessPoint.html#gdbus-property-org-freedesktop-NetworkManager-AccessPoint.Strength It seems that the old D-Bus implementation returned an array. With dbus-next a integer is returned, so no list indexing required. * Support signals and remove no longer used tests and code * Pass rauc update file path as string That is what the interface is expecting, otherwise the new lib chocks on the Pathlib type. * Support Network configuration with dbus-next Assemble Python native objects and pass them to dbus-next. Use dbus-next specific Variant class where necessary. * Use org.freedesktop.NetworkManager.Connection.Active.StateChanged org.freedesktop.NetworkManager.Connection.Active.PropertyChanged is depricated. Also it seems that StateChanged leads to fewer and more accurate signals. * Pass correct data type to RequestScan. RequestScan expects an option dictionary. Pass an empty option dictionary to it. * Update unit tests Replace gdbus specific fixtures with json files representing the return values. Those can be easily converted into native Python objects. * Rename D-Bus utils module gdbus to dbus
2021-10-18 23:06:44 +02:00
# utils/dbus
2018-04-22 09:59:43 +02:00
2018-04-22 09:59:43 +02:00
class DBusError(HassioError):
Use Python dbus-next D-Bus library (#3234) * Use the correct interface name to get properties of systemd It seems that gdbus (or systemd) automatically pick the correct interface and return the properties. However, dbussy requires the correct interface name to get all properties. * Don't expect array from Strength property The property returns a type "y" which equates to "guchar": https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.AccessPoint.html#gdbus-property-org-freedesktop-NetworkManager-AccessPoint.Strength It seems that the old D-Bus implementation returned an array. With dbus-next a integer is returned, so no list indexing required. * Support signals and remove no longer used tests and code * Pass rauc update file path as string That is what the interface is expecting, otherwise the new lib chocks on the Pathlib type. * Support Network configuration with dbus-next Assemble Python native objects and pass them to dbus-next. Use dbus-next specific Variant class where necessary. * Use org.freedesktop.NetworkManager.Connection.Active.StateChanged org.freedesktop.NetworkManager.Connection.Active.PropertyChanged is depricated. Also it seems that StateChanged leads to fewer and more accurate signals. * Pass correct data type to RequestScan. RequestScan expects an option dictionary. Pass an empty option dictionary to it. * Update unit tests Replace gdbus specific fixtures with json files representing the return values. Those can be easily converted into native Python objects. * Rename D-Bus utils module gdbus to dbus
2021-10-18 23:06:44 +02:00
"""D-Bus generic error."""
2018-04-22 09:59:43 +02:00
2018-04-26 11:33:43 +02:00
class DBusNotConnectedError(HostNotSupportedError):
Use Python dbus-next D-Bus library (#3234) * Use the correct interface name to get properties of systemd It seems that gdbus (or systemd) automatically pick the correct interface and return the properties. However, dbussy requires the correct interface name to get all properties. * Don't expect array from Strength property The property returns a type "y" which equates to "guchar": https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.AccessPoint.html#gdbus-property-org-freedesktop-NetworkManager-AccessPoint.Strength It seems that the old D-Bus implementation returned an array. With dbus-next a integer is returned, so no list indexing required. * Support signals and remove no longer used tests and code * Pass rauc update file path as string That is what the interface is expecting, otherwise the new lib chocks on the Pathlib type. * Support Network configuration with dbus-next Assemble Python native objects and pass them to dbus-next. Use dbus-next specific Variant class where necessary. * Use org.freedesktop.NetworkManager.Connection.Active.StateChanged org.freedesktop.NetworkManager.Connection.Active.PropertyChanged is depricated. Also it seems that StateChanged leads to fewer and more accurate signals. * Pass correct data type to RequestScan. RequestScan expects an option dictionary. Pass an empty option dictionary to it. * Update unit tests Replace gdbus specific fixtures with json files representing the return values. Those can be easily converted into native Python objects. * Rename D-Bus utils module gdbus to dbus
2021-10-18 23:06:44 +02:00
"""D-Bus is not connected and call a method."""
2018-04-22 09:59:43 +02:00
class DBusInterfaceError(HassioNotSupportedError):
Use Python dbus-next D-Bus library (#3234) * Use the correct interface name to get properties of systemd It seems that gdbus (or systemd) automatically pick the correct interface and return the properties. However, dbussy requires the correct interface name to get all properties. * Don't expect array from Strength property The property returns a type "y" which equates to "guchar": https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.AccessPoint.html#gdbus-property-org-freedesktop-NetworkManager-AccessPoint.Strength It seems that the old D-Bus implementation returned an array. With dbus-next a integer is returned, so no list indexing required. * Support signals and remove no longer used tests and code * Pass rauc update file path as string That is what the interface is expecting, otherwise the new lib chocks on the Pathlib type. * Support Network configuration with dbus-next Assemble Python native objects and pass them to dbus-next. Use dbus-next specific Variant class where necessary. * Use org.freedesktop.NetworkManager.Connection.Active.StateChanged org.freedesktop.NetworkManager.Connection.Active.PropertyChanged is depricated. Also it seems that StateChanged leads to fewer and more accurate signals. * Pass correct data type to RequestScan. RequestScan expects an option dictionary. Pass an empty option dictionary to it. * Update unit tests Replace gdbus specific fixtures with json files representing the return values. Those can be easily converted into native Python objects. * Rename D-Bus utils module gdbus to dbus
2021-10-18 23:06:44 +02:00
"""D-Bus interface not connected."""
class DBusObjectError(HassioNotSupportedError):
"""D-Bus object not defined."""
2018-04-22 09:59:43 +02:00
class DBusInterfaceMethodError(DBusInterfaceError):
"""D-Bus method not defined or input does not match signature."""
class DBusInterfacePropertyError(DBusInterfaceError):
"""D-Bus property not defined or is read-only."""
class DBusInterfaceSignalError(DBusInterfaceError):
"""D-Bus signal not defined."""
2018-04-22 09:59:43 +02:00
class DBusParseError(DBusError):
Use Python dbus-next D-Bus library (#3234) * Use the correct interface name to get properties of systemd It seems that gdbus (or systemd) automatically pick the correct interface and return the properties. However, dbussy requires the correct interface name to get all properties. * Don't expect array from Strength property The property returns a type "y" which equates to "guchar": https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.AccessPoint.html#gdbus-property-org-freedesktop-NetworkManager-AccessPoint.Strength It seems that the old D-Bus implementation returned an array. With dbus-next a integer is returned, so no list indexing required. * Support signals and remove no longer used tests and code * Pass rauc update file path as string That is what the interface is expecting, otherwise the new lib chocks on the Pathlib type. * Support Network configuration with dbus-next Assemble Python native objects and pass them to dbus-next. Use dbus-next specific Variant class where necessary. * Use org.freedesktop.NetworkManager.Connection.Active.StateChanged org.freedesktop.NetworkManager.Connection.Active.PropertyChanged is depricated. Also it seems that StateChanged leads to fewer and more accurate signals. * Pass correct data type to RequestScan. RequestScan expects an option dictionary. Pass an empty option dictionary to it. * Update unit tests Replace gdbus specific fixtures with json files representing the return values. Those can be easily converted into native Python objects. * Rename D-Bus utils module gdbus to dbus
2021-10-18 23:06:44 +02:00
"""D-Bus parse error."""
class DBusTimeoutError(DBusError):
"""D-Bus call timed out."""
2023-04-28 05:52:55 +02:00
class DBusFatalError(DBusError):
"""D-Bus call going wrong.
Type field contains specific error from D-Bus for interface specific errors (like Systemd ones).
"""
def __init__(
self,
message: str | None = None,
logger: Callable[..., None] | None = None,
type_: str | None = None,
) -> None:
"""Initialize object."""
super().__init__(message, logger)
self.type = type_
# dbus/systemd
class DBusSystemdNoSuchUnit(DBusError):
"""Systemd unit does not exist."""
# util/apparmor
class AppArmorError(HostAppArmorError):
"""General AppArmor error."""
class AppArmorFileError(AppArmorError):
"""AppArmor profile file error."""
class AppArmorInvalidError(AppArmorError):
"""AppArmor profile validate error."""
# util/boards
class BoardInvalidError(DBusObjectError):
"""System does not use the board specified."""
# util/common
class ConfigurationFileError(HassioError):
"""Invalid JSON or YAML file."""
# util/json
class JsonFileError(ConfigurationFileError):
"""Invalid JSON file."""
# util/yaml
class YamlFileError(ConfigurationFileError):
"""Invalid YAML file."""
# util/pwned
class PwnedError(HassioError):
"""Errors while checking pwned passwords."""
class PwnedSecret(PwnedError):
"""Pwned secrets found."""
class PwnedConnectivityError(PwnedError):
"""Connectivity errors while checking pwned passwords."""
# util/codenotary
class CodeNotaryError(HassioError):
"""Error general with CodeNotary."""
class CodeNotaryUntrusted(CodeNotaryError):
"""Error on untrusted content."""
class CodeNotaryBackendError(CodeNotaryError):
"""CodeNotary backend error happening."""
# util/whoami
class WhoamiError(HassioError):
"""Error while using whoami."""
class WhoamiSSLError(WhoamiError):
"""Error with the SSL certificate."""
class WhoamiConnectivityError(WhoamiError):
"""Connectivity errors while using whoami."""
# docker/api
class DockerError(HassioError):
"""Docker API/Transport errors."""
class DockerAPIError(DockerError):
"""Docker API error."""
class DockerRequestError(DockerError):
"""Dockerd OS issues."""
class DockerTrustError(DockerError):
"""Raise if images are not trusted."""
class DockerNotFound(DockerError):
"""Docker object don't Exists."""
# Hardware
Next generation hardware handling (#2429) * Next generation hardware handling * need daemon for some details * fix tests * fix wrong coresys lookup * test initial import * test device lookup * validate if device exists * Add cgroups rules manager * mapping udev from host * Modify validation/options handling * lookup devices * add support for host udev mapping * next * Add policy support to add-ons * Depricate hardware trigger call * next cleanup round * detect USB linking * optimize * readd udev utils for backwards compatibility * fix tests * Add more tests * fix tests * Make device explicit * Add filter * work on tests * Add migration step * clean out auto_uart * Fix all tests * Expose all device information * small improvment * Fix loop over right devices * Use migration for new device format * Update rootfs/etc/cont-init.d/udev.sh Co-authored-by: Franck Nijhof <git@frenck.dev> * Fix old helper * Fix API * add helper for by-id * fix tests * Fix serial helper * Fix hardware API schema * Hide some virtual devices from tracking * Apply suggestions from code review Co-authored-by: Stefan Agner <stefan@agner.ch> * Update supervisor/addons/validate.py Co-authored-by: Stefan Agner <stefan@agner.ch> * Update supervisor/addons/validate.py Co-authored-by: Stefan Agner <stefan@agner.ch> * fix lint * Apply suggestions from code review Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * Apply suggestions from code review Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * fix black * fix lint Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Stefan Agner <stefan@agner.ch> Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
2021-01-28 15:26:56 +01:00
class HardwareError(HassioError):
"""General Hardware Error on Supervisor."""
class HardwareNotFound(HardwareError):
"""Hardware path or device doesn't exist on the Host."""
class HardwareNotSupportedError(HassioNotSupportedError):
"""Raise if hardware function is not supported."""
# Pulse Audio
class PulseAudioError(HassioError):
"""Raise if an sound error is happening."""
# Resolution
class ResolutionError(HassioError):
"""Raise if an error is happning on resoltuion."""
class ResolutionCheckError(ResolutionError):
"""Raise when there are an issue managing checks."""
class ResolutionNotFound(ResolutionError):
"""Raise if suggestion/issue was not found."""
class ResolutionFixupError(HassioError):
"""Rasie if a fixup fails."""
2020-12-03 21:06:48 +01:00
class ResolutionFixupJobError(ResolutionFixupError, JobException):
"""Raise on job error."""
# Store
class StoreError(HassioError):
"""Raise if an error on store is happening."""
class StoreGitError(StoreError):
"""Raise if something on git is happening."""
class StoreGitCloneError(StoreGitError):
"""Raise if error occurred while cloning repository."""
class StoreNotFound(StoreError):
"""Raise if slug is not known."""
2020-12-03 21:06:48 +01:00
class StoreJobError(StoreError, JobException):
"""Raise on job error with git."""
class StoreInvalidAddonRepo(StoreError):
"""Raise on invalid addon repo."""
# Backup
class BackupError(HassioError):
"""Raise if an error during backup is happening."""
class HomeAssistantBackupError(BackupError, HomeAssistantError):
"""Raise if an error during Home Assistant Core backup is happening."""
# Security
class SecurityError(HassioError):
"""Raise if an error during security checks are happening."""
class SecurityJobError(SecurityError, JobException):
"""Raise on Security job error."""
2023-04-28 05:52:55 +02:00
# Mount
class MountError(HassioError):
"""Raise on an error related to mounting/unmounting."""
class MountActivationError(MountError):
"""Raise on mount not reaching active state after mount/reload."""
2023-04-28 05:52:55 +02:00
class MountInvalidError(MountError):
"""Raise on invalid mount attempt."""
class MountNotFound(MountError):
"""Raise on mount not found."""