Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 1 | # 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 | |
| 20 | class VelaError(Exception): |
| 21 | """Base class for vela exceptions""" |
| 22 | |
| 23 | def __init__(self, data): |
Tim Hall | d8339a7 | 2021-05-27 18:49:40 +0100 | [diff] [blame] | 24 | self.data = f"Error: {data}" |
Louis Verhaard | 024c355 | 2021-03-17 14:26:34 +0100 | [diff] [blame] | 25 | self.error_msg = data |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 26 | |
| 27 | def __str__(self): |
| 28 | return repr(self.data) |
| 29 | |
| 30 | |
| 31 | class InputFileError(VelaError): |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 32 | """Raised when reading an input file results in errors""" |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 33 | |
| 34 | def __init__(self, file_name, msg): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 35 | super().__init__(f"Reading input file '{file_name}': {msg}") |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 36 | |
| 37 | |
| 38 | class UnsupportedFeatureError(VelaError): |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 39 | """Raised when the input network uses non-supported features that cannot be handled""" |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 40 | |
| 41 | def __init__(self, data): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 42 | super().__init__(f"Input network uses a feature that is currently not supported: {data}") |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 43 | |
| 44 | |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 45 | class 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 Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 52 | |
| 53 | def __init__(self, option, option_value, msg): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 54 | super().__init__(f"Incorrect argument to CLI option {option}={option_value}: {msg}") |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | class 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 McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 66 | data = f"Invalid configuration of {option}={option_value}" |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 67 | if option_valid_values is not None: |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 68 | data += f" (must be {option_valid_values})" |
| 69 | super().__init__(data) |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 70 | |
| 71 | |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 72 | class AllocationError(VelaError): |
| 73 | """Raised when allocation fails""" |
| 74 | |
| 75 | def __init__(self, msg): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 76 | super().__init__(f"Allocation failed: {msg}") |