From 46173f284cd971c4201969fa9fd35121c7cf7a3a Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 4 Aug 2022 12:51:27 -0400 Subject: T2719: add an exception hierarchy for op mode errors --- python/vyos/opmode.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'python') diff --git a/python/vyos/opmode.py b/python/vyos/opmode.py index 0af4359c6..628f7b3a2 100644 --- a/python/vyos/opmode.py +++ b/python/vyos/opmode.py @@ -18,6 +18,33 @@ import sys import typing +class Error(Exception): + """ Any error that makes requested operation impossible to complete + for reasons unrelated to the user input or script logic. + """ + pass + +class UnconfiguredSubsystem(Error): + """ Requested operation is valid, but cannot be completed + because corresponding subsystem is not configured and running. + """ + pass + +class DataUnavailable(Error): + """ Requested operation is valid, but cannot be completed + because data for it is not available. + This error MAY be treated as temporary because such issues + are often caused by transient events such as service restarts. + """ + pass + +class PermissionDenied(Error): + """ Requested operation is valid, but the caller has no permission + to perform it. + """ + pass + + def _is_op_mode_function_name(name): if re.match(r"^(show|clear|reset|restart)", name): return True -- cgit v1.2.3