blob: 04468c90985822606dddd3bb11a5ef041e98128c [file] [log] [blame]
Louis Verhaard7db78962020-05-25 15:05:26 +02001# Copyright (C) 2020 Arm Limited or its affiliates. All rights reserved.
2#
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.
16# Description:
17# Defines custom exceptions.
18
19
20class VelaError(Exception):
21 """Base class for vela exceptions"""
22
23 def __init__(self, data):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000024 self.data = f"Error! {data}"
Louis Verhaard7db78962020-05-25 15:05:26 +020025
26 def __str__(self):
27 return repr(self.data)
28
29
30class InputFileError(VelaError):
Tim Hall1bd531d2020-11-01 20:59:36 +000031 """Raised when reading an input file results in errors"""
Louis Verhaard7db78962020-05-25 15:05:26 +020032
33 def __init__(self, file_name, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000034 super().__init__(f"Reading input file '{file_name}': {msg}")
Louis Verhaard7db78962020-05-25 15:05:26 +020035
36
37class UnsupportedFeatureError(VelaError):
Tim Hall1bd531d2020-11-01 20:59:36 +000038 """Raised when the input network uses non-supported features that cannot be handled"""
Louis Verhaard7db78962020-05-25 15:05:26 +020039
40 def __init__(self, data):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000041 super().__init__(f"Input network uses a feature that is currently not supported: {data}")
Louis Verhaard7db78962020-05-25 15:05:26 +020042
43
Tim Hall1bd531d2020-11-01 20:59:36 +000044class CliOptionError(VelaError):
45 """Raised for errors encountered with a command line option
46
47 :param option: str object that contains the name of the command line option
48 :param option_value: the command line option that resulted in the error
49 :param msg: str object that contains a description of the specific error encountered
50 """
Louis Verhaard7db78962020-05-25 15:05:26 +020051
52 def __init__(self, option, option_value, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000053 super().__init__(f"Incorrect argument to CLI option {option}={option_value}: {msg}")
Tim Hall1bd531d2020-11-01 20:59:36 +000054
55
56class ConfigOptionError(VelaError):
57 """Raised for errors encountered with a configuration option
58
59 :param option: str object that contains the name of the configuration option
60 :param option_value: the configuration option that resulted in the error
61 :param option_valid_values (optional): str object that contains the valid configuration option values
62 """
63
64 def __init__(self, option, option_value, option_valid_values=None):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000065 data = f"Invalid configuration of {option}={option_value}"
Tim Hall1bd531d2020-11-01 20:59:36 +000066 if option_valid_values is not None:
Michael McGeagh7a6f8432020-12-02 15:29:22 +000067 data += f" (must be {option_valid_values})"
68 super().__init__(data)
Tim Hallc8310b12020-06-17 14:53:11 +010069
70
Jacob Bohlin0628a8c2020-08-28 13:25:14 +020071class AllocationError(VelaError):
72 """Raised when allocation fails"""
73
74 def __init__(self, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000075 super().__init__(f"Allocation failed: {msg}")