blob: bf3bb4d339ba8870b27b9913d6405938fd63bbe2 [file] [log] [blame]
Rickard Bolinbc6ee582022-11-04 08:24:29 +00001# SPDX-FileCopyrightText: Copyright 2020-2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
Louis Verhaard7db78962020-05-25 15:05:26 +02002#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the License); you may
6# not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an AS IS BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Rickard Bolinbc6ee582022-11-04 08:24:29 +000016#
Louis Verhaard7db78962020-05-25 15:05:26 +020017# Description:
18# Defines custom exceptions.
19
20
21class VelaError(Exception):
22 """Base class for vela exceptions"""
23
24 def __init__(self, data):
Tim Halld8339a72021-05-27 18:49:40 +010025 self.data = f"Error: {data}"
Louis Verhaard024c3552021-03-17 14:26:34 +010026 self.error_msg = data
Louis Verhaard7db78962020-05-25 15:05:26 +020027
28 def __str__(self):
29 return repr(self.data)
30
31
32class InputFileError(VelaError):
Tim Hall1bd531d2020-11-01 20:59:36 +000033 """Raised when reading an input file results in errors"""
Louis Verhaard7db78962020-05-25 15:05:26 +020034
35 def __init__(self, file_name, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000036 super().__init__(f"Reading input file '{file_name}': {msg}")
Louis Verhaard7db78962020-05-25 15:05:26 +020037
38
39class UnsupportedFeatureError(VelaError):
Tim Hall1bd531d2020-11-01 20:59:36 +000040 """Raised when the input network uses non-supported features that cannot be handled"""
Louis Verhaard7db78962020-05-25 15:05:26 +020041
42 def __init__(self, data):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000043 super().__init__(f"Input network uses a feature that is currently not supported: {data}")
Louis Verhaard7db78962020-05-25 15:05:26 +020044
45
Tim Hall1bd531d2020-11-01 20:59:36 +000046class CliOptionError(VelaError):
47 """Raised for errors encountered with a command line option
48
49 :param option: str object that contains the name of the command line option
50 :param option_value: the command line option that resulted in the error
51 :param msg: str object that contains a description of the specific error encountered
52 """
Louis Verhaard7db78962020-05-25 15:05:26 +020053
54 def __init__(self, option, option_value, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000055 super().__init__(f"Incorrect argument to CLI option {option}={option_value}: {msg}")
Tim Hall1bd531d2020-11-01 20:59:36 +000056
57
58class ConfigOptionError(VelaError):
59 """Raised for errors encountered with a configuration option
60
61 :param option: str object that contains the name of the configuration option
62 :param option_value: the configuration option that resulted in the error
63 :param option_valid_values (optional): str object that contains the valid configuration option values
64 """
65
66 def __init__(self, option, option_value, option_valid_values=None):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000067 data = f"Invalid configuration of {option}={option_value}"
Tim Hall1bd531d2020-11-01 20:59:36 +000068 if option_valid_values is not None:
Michael McGeagh7a6f8432020-12-02 15:29:22 +000069 data += f" (must be {option_valid_values})"
70 super().__init__(data)
Tim Hallc8310b12020-06-17 14:53:11 +010071
72
Jacob Bohlin0628a8c2020-08-28 13:25:14 +020073class AllocationError(VelaError):
74 """Raised when allocation fails"""
75
76 def __init__(self, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000077 super().__init__(f"Allocation failed: {msg}")