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): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 24 | self.data = f"Error! {data}" |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 25 | |
| 26 | def __str__(self): |
| 27 | return repr(self.data) |
| 28 | |
| 29 | |
| 30 | class InputFileError(VelaError): |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 31 | """Raised when reading an input file results in errors""" |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 32 | |
| 33 | def __init__(self, file_name, msg): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 34 | super().__init__(f"Reading input file '{file_name}': {msg}") |
Louis Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 35 | |
| 36 | |
| 37 | class UnsupportedFeatureError(VelaError): |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 38 | """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] | 39 | |
| 40 | def __init__(self, data): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 41 | 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] | 42 | |
| 43 | |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 44 | class 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 Verhaard | 7db7896 | 2020-05-25 15:05:26 +0200 | [diff] [blame] | 51 | |
| 52 | def __init__(self, option, option_value, msg): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 53 | super().__init__(f"Incorrect argument to CLI option {option}={option_value}: {msg}") |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 54 | |
| 55 | |
| 56 | class 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 McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 65 | data = f"Invalid configuration of {option}={option_value}" |
Tim Hall | 1bd531d | 2020-11-01 20:59:36 +0000 | [diff] [blame] | 66 | if option_valid_values is not None: |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 67 | data += f" (must be {option_valid_values})" |
| 68 | super().__init__(data) |
Tim Hall | c8310b1 | 2020-06-17 14:53:11 +0100 | [diff] [blame] | 69 | |
| 70 | |
Jacob Bohlin | 0628a8c | 2020-08-28 13:25:14 +0200 | [diff] [blame] | 71 | class AllocationError(VelaError): |
| 72 | """Raised when allocation fails""" |
| 73 | |
| 74 | def __init__(self, msg): |
Michael McGeagh | 7a6f843 | 2020-12-02 15:29:22 +0000 | [diff] [blame] | 75 | super().__init__(f"Allocation failed: {msg}") |