File: pyverbs_error.py

package info (click to toggle)
rdma-core 33.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,844 kB
  • sloc: ansic: 145,804; python: 5,688; sh: 2,761; perl: 1,465; makefile: 73
file content (47 lines) | stat: -rw-r--r-- 1,503 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
# Copyright (c) 2018, Mellanox Technologies. All rights reserved.
import os


class PyverbsError(Exception):
    """
    Base exception class for Pyverbs. Inherited by PyverbsRDMAError (for errors
    returned by rdma-core) and PyverbsUserError (for user-related errors
    found by Pyverbs,  e.g. non-existing device name).
    """
    def __init__(self, msg, error_code = -1):
        """
        Initializes a PyverbsError instance
        :param msg: The exception's message
        :param error_code: errno value
        """
        if error_code != -1:
            msg = '{msg}. Errno: {err}, {err_str}'.\
                format(msg=msg, err=error_code, err_str=os.strerror(error_code))
        super(PyverbsError, self).__init__(msg)

class PyverbsRDMAError(PyverbsError):
    """
    This exception is raised when an rdma-core function returns an error.
    """
    def __init__(self, msg, error_code = -1):
        super(PyverbsRDMAError, self).__init__(msg, error_code)
        self._error_code = error_code

    @property
    def error_code(self):
        return self._error_code


class PyverbsUserError(PyverbsError):
    """
    This exception is raised when Pyverbs encounters an error resulting from
    user's action or input.
    """
    def __init__(self, msg):
        """
        Initializes a PyverbsUserError instance
        :param msg: The exception's message
        """
        super(PyverbsUserError, self).__init__(msg)