blob: 9553c80d7fe44ade96486edfbe18b4ce6e151cc7 [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):
Tim Halld8339a72021-05-27 18:49:40 +010024 self.data = f"Error: {data}"
Louis Verhaard024c3552021-03-17 14:26:34 +010025 self.error_msg = data
Louis Verhaard7db78962020-05-25 15:05:26 +020026
27 def __str__(self):
28 return repr(self.data)
29
30
31class InputFileError(VelaError):
Tim Hall1bd531d2020-11-01 20:59:36 +000032 """Raised when reading an input file results in errors"""
Louis Verhaard7db78962020-05-25 15:05:26 +020033
34 def __init__(self, file_name, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000035 super().__init__(f"Reading input file '{file_name}': {msg}")
Louis Verhaard7db78962020-05-25 15:05:26 +020036
37
38class UnsupportedFeatureError(VelaError):
Tim Hall1bd531d2020-11-01 20:59:36 +000039 """Raised when the input network uses non-supported features that cannot be handled"""
Louis Verhaard7db78962020-05-25 15:05:26 +020040
41 def __init__(self, data):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000042 super().__init__(f"Input network uses a feature that is currently not supported: {data}")
Louis Verhaard7db78962020-05-25 15:05:26 +020043
44
Tim Hall1bd531d2020-11-01 20:59:36 +000045class CliOptionError(VelaError):
46 """Raised for errors encountered with a command line option
47
48 :param option: str object that contains the name of the command line option
49 :param option_value: the command line option that resulted in the error
50 :param msg: str object that contains a description of the specific error encountered
51 """
Louis Verhaard7db78962020-05-25 15:05:26 +020052
53 def __init__(self, option, option_value, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000054 super().__init__(f"Incorrect argument to CLI option {option}={option_value}: {msg}")
Tim Hall1bd531d2020-11-01 20:59:36 +000055
56
57class ConfigOptionError(VelaError):
58 """Raised for errors encountered with a configuration option
59
60 :param option: str object that contains the name of the configuration option
61 :param option_value: the configuration option that resulted in the error
62 :param option_valid_values (optional): str object that contains the valid configuration option values
63 """
64
65 def __init__(self, option, option_value, option_valid_values=None):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000066 data = f"Invalid configuration of {option}={option_value}"
Tim Hall1bd531d2020-11-01 20:59:36 +000067 if option_valid_values is not None:
Michael McGeagh7a6f8432020-12-02 15:29:22 +000068 data += f" (must be {option_valid_values})"
69 super().__init__(data)
Tim Hallc8310b12020-06-17 14:53:11 +010070
71
Jacob Bohlin0628a8c2020-08-28 13:25:14 +020072class AllocationError(VelaError):
73 """Raised when allocation fails"""
74
75 def __init__(self, msg):
Michael McGeagh7a6f8432020-12-02 15:29:22 +000076 super().__init__(f"Allocation failed: {msg}")