File: exception.hpp

package info (click to toggle)
dnf5 5.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,960 kB
  • sloc: cpp: 94,312; python: 3,370; xml: 1,073; ruby: 600; sql: 250; ansic: 232; sh: 104; perl: 62; makefile: 30
file content (137 lines) | stat: -rw-r--r-- 6,076 bytes parent folder | download
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef _BINDINGS_LIBDNF5_EXCEPTINON_HPP_
#define _BINDINGS_LIBDNF5_EXCEPTINON_HPP_

#include "libdnf5/base/transaction_errors.hpp"
#include "libdnf5/common/exception.hpp"
#include "libdnf5/comps/group/package_errors.hpp"
#include "libdnf5/conf/config_parser_errors.hpp"
#include "libdnf5/conf/option_binds_errors.hpp"
#include "libdnf5/conf/option_errors.hpp"
#include "libdnf5/conf/option_path_errors.hpp"
#include "libdnf5/conf/vars_errors.hpp"
//#include "libdnf5/module/module_errors.hpp"
#include "libdnf5/repo/file_downloader_errors.hpp"
#include "libdnf5/repo/package_downloader_errors.hpp"
#include "libdnf5/repo/repo_cache_errors.hpp"
#include "libdnf5/repo/repo_errors.hpp"
#include "libdnf5/rpm/nevra_errors.hpp"
#include "libdnf5/rpm/rpm_signature_errors.hpp"
#include "libdnf5/transaction/transaction_errors.hpp"
#include "libdnf5/transaction/transaction_item_errors.hpp"
#include "libdnf5/utils/bgettext/bgettext-mark.h"


/// Class for wrapping exceptions not defined in libdnf5. For example, std::* exceptions.
class NonLibdnf5Exception : public std::runtime_error {
public:
    using runtime_error::runtime_error;
};


#if defined(SWIGPYTHON)

#define swig_exception(e, Type)                     \
    auto * ex = new Type(e);                        \
    auto ex_swig_type = SWIG_TypeQuery(#Type " *"); \
    SWIG_Python_Raise(SWIG_NewPointerObj(ex, ex_swig_type, SWIG_POINTER_OWN), #Type, ex_swig_type);

#elif defined(SWIGPERL)

#define swig_exception(e, Type)                     \
    auto * ex = new Type(e);                        \
    auto ex_swig_type = SWIG_TypeQuery(#Type " *"); \
    sv_setsv(get_sv("@", GV_ADD), SWIG_NewPointerObj(ex, ex_swig_type, SWIG_POINTER_OWN));

#elif defined(SWIGRUBY)

#define swig_exception(e, Type)                     \
    auto * ex = new Type(e);                        \
    auto ex_swig_type = SWIG_TypeQuery(#Type " *"); \
    rb_exc_raise(SWIG_Ruby_ExceptionType(ex_swig_type, SWIG_NewPointerObj(ex, ex_swig_type, SWIG_POINTER_OWN)));

#endif

#define swig_if_exception(e, Type)                                                  \
    if (auto * oe = dynamic_cast<const Type *>(&e)) {                               \
        if (auto * ne = dynamic_cast<const libdnf5::NestedException<Type> *>(&e)) { \
            swig_exception(*ne, libdnf5::NestedException<Type>);                    \
        } else {                                                                    \
            swig_exception(*oe, Type);                                              \
        }                                                                           \
        break;                                                                      \
    }

static void create_swig_exception(const std::exception & e) {
    do {
        swig_if_exception(e, libdnf5::base::TransactionError);

        swig_if_exception(e, libdnf5::comps::InvalidPackageType);

        swig_if_exception(e, libdnf5::repo::FileDownloadError);
        swig_if_exception(e, libdnf5::repo::PackageDownloadError);
        swig_if_exception(e, libdnf5::repo::RepoCacheError);

        swig_if_exception(e, libdnf5::repo::RepoCacheonlyError);
        swig_if_exception(e, libdnf5::repo::RepoDownloadError);
        swig_if_exception(e, libdnf5::repo::RepoPgpError);
        swig_if_exception(e, libdnf5::repo::RepoRpmError);
        swig_if_exception(e, libdnf5::repo::RepoCompsError);
        swig_if_exception(e, libdnf5::repo::RepoIdAlreadyExistsError);
        swig_if_exception(e, libdnf5::repo::RepoError);

        swig_if_exception(e, libdnf5::rpm::NevraIncorrectInputError);
        swig_if_exception(e, libdnf5::rpm::SignatureCheckError);
        swig_if_exception(e, libdnf5::rpm::KeyImportError);

        swig_if_exception(e, libdnf5::transaction::InvalidTransactionItemAction);
        swig_if_exception(e, libdnf5::transaction::InvalidTransactionItemReason);
        swig_if_exception(e, libdnf5::transaction::InvalidTransactionItemState);
        swig_if_exception(e, libdnf5::transaction::InvalidTransactionItemType);
        swig_if_exception(e, libdnf5::transaction::InvalidTransactionState);

        swig_if_exception(e, libdnf5::InaccessibleConfigError);
        swig_if_exception(e, libdnf5::MissingConfigError);
        swig_if_exception(e, libdnf5::InvalidConfigError);

        swig_if_exception(e, libdnf5::ConfigParserSectionNotFoundError);
        swig_if_exception(e, libdnf5::ConfigParserOptionNotFoundError);
        swig_if_exception(e, libdnf5::ConfigParserError);

        swig_if_exception(e, libdnf5::OptionValueNotSetError);
        swig_if_exception(e, libdnf5::OptionValueNotAllowedError);
        swig_if_exception(e, libdnf5::OptionInvalidValueError);
        swig_if_exception(e, libdnf5::OptionError);

        swig_if_exception(e, libdnf5::OptionBindsOptionNotFoundError);
        swig_if_exception(e, libdnf5::OptionBindsOptionAlreadyExistsError);
        swig_if_exception(e, libdnf5::OptionBindsError);

        swig_if_exception(e, libdnf5::ReadOnlyVariableError);

        swig_if_exception(e, libdnf5::FileSystemError);
        swig_if_exception(e, libdnf5::SystemError);
        swig_if_exception(e, libdnf5::RuntimeError);
        swig_if_exception(e, libdnf5::Error);
        swig_if_exception(e, libdnf5::UserAssertionError);
        swig_if_exception(e, libdnf5::AssertionError);

        // We caught an exception not defined in libdnf5. We transform it into a libdnf5::NonLibdnf5Exception.
        if (auto * oe = dynamic_cast<const std::exception *>(&e)) {
            try {
                std::rethrow_if_nested(e);
            } catch (const std::exception &) {
                swig_exception(
                    libdnf5::NestedException<NonLibdnf5Exception>(NonLibdnf5Exception(oe->what())),
                    libdnf5::NestedException<NonLibdnf5Exception>);
                break;
            }
            swig_exception(NonLibdnf5Exception(oe->what()), NonLibdnf5Exception);
            break;
        }
    } while (false);
}

#undef swig_if_exception
#undef swig_exception

#endif