Coverage for birdplan/exceptions.py: 71%
14 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
1#
2# SPDX-License-Identifier: GPL-3.0-or-later
3#
4# Copyright (c) 2019-2024, AllWorldIT
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
19"""BirdPlan exceptions."""
21import argparse
22from typing import Any
24__all__ = ["BirdPlanError", "BirdPlanErrorUsage"]
27class BirdPlanError(RuntimeError):
28 """BirdPlan runtime error."""
31class BirdPlanErrorUsage(RuntimeError):
32 """BirdPlan runtime error, raised when used incorrectly."""
34 message: str
35 parser: argparse.ArgumentParser
37 def __init__(self, *args: Any):
38 """Initialize object."""
40 super().__init__(*args)
42 self.message = args[0]
43 self.parser = args[1]
45 def __str__(self) -> str:
46 """Return string representation of the exception."""
48 return f"{self.message}\n\n{self.parser.format_help()}"