• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

llnl / dftracer-utils / 28496595030

01 Jul 2026 05:50AM UTC coverage: 50.727% (-1.6%) from 52.278%
28496595030

Pull #83

github

web-flow
Merge 8f1ff4df5 into 2efed6649
Pull Request #83: refactor and improve code QoL

31872 of 80367 branches covered (39.66%)

Branch coverage included in aggregate %.

770 of 1591 new or added lines in 85 files covered. (48.4%)

5070 existing lines in 182 files now uncovered.

32742 of 47009 relevant lines covered (69.65%)

9887.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.56
/src/dftracer/utils/python/py_errors.cpp
1
#include <dftracer/utils/python/py_errors.h>
2

3
#include <stdexcept>
4
#include <string>
5

6
PyObject *g_dft_error = nullptr;
7
PyObject *g_dft_value_error = nullptr;
8
PyObject *g_dft_not_found_error = nullptr;
9
PyObject *g_dft_io_error = nullptr;
10
PyObject *g_dft_parse_error = nullptr;
11
PyObject *g_dft_compression_error = nullptr;
12
PyObject *g_dft_query_error = nullptr;
13
PyObject *g_dft_reader_error = nullptr;
14
PyObject *g_dft_indexer_error = nullptr;
15
PyObject *g_dft_pipeline_error = nullptr;
16
PyObject *g_dft_aggregation_error = nullptr;
17

18
using dftracer::utils::ErrorCode;
19

20
namespace {
21

22
// Create exception "dftracer_utils_ext.<short_name>", register it on m, and
23
// keep a strong ref in *slot.
24
int add_exc(PyObject *m, const char *short_name, PyObject *base,
11✔
25
            PyObject **slot) {
26
    const std::string qualified =
27
        std::string("dftracer_utils_ext.") + short_name;
11!
28
    PyObject *exc = PyErr_NewException(qualified.c_str(), base, nullptr);
11!
29
    if (exc == nullptr) return -1;
11!
30
    Py_INCREF(exc);  // keep one strong ref in *slot in addition to the module's
11!
31
    if (PyModule_AddObject(m, short_name, exc) < 0) {
11!
NEW
32
        Py_DECREF(exc);  // undo AddObject's intended steal
×
NEW
33
        Py_DECREF(exc);  // undo our INCREF
×
NEW
34
        return -1;
×
35
    }
36
    *slot = exc;
11✔
37
    return 0;
11✔
38
}
11✔
39

40
}  // namespace
41

42
int init_py_errors(PyObject *m) {
1✔
43
    if (add_exc(m, "DFTUtilsError", PyExc_RuntimeError, &g_dft_error) < 0)
1!
NEW
44
        return -1;
×
45
    if (add_exc(m, "DFTUtilsValueError", g_dft_error, &g_dft_value_error) < 0)
1!
NEW
46
        return -1;
×
47
    if (add_exc(m, "DFTUtilsNotFoundError", g_dft_error,
2!
48
                &g_dft_not_found_error) < 0)
1✔
NEW
49
        return -1;
×
50
    if (add_exc(m, "DFTUtilsIOError", g_dft_error, &g_dft_io_error) < 0)
1!
NEW
51
        return -1;
×
52
    if (add_exc(m, "DFTUtilsParseError", g_dft_error, &g_dft_parse_error) < 0)
1!
NEW
53
        return -1;
×
54
    if (add_exc(m, "DFTUtilsCompressionError", g_dft_error,
2!
55
                &g_dft_compression_error) < 0)
1✔
NEW
56
        return -1;
×
57
    if (add_exc(m, "DFTUtilsQueryError", g_dft_error, &g_dft_query_error) < 0)
1!
NEW
58
        return -1;
×
59
    if (add_exc(m, "DFTUtilsReaderError", g_dft_error, &g_dft_reader_error) < 0)
1!
NEW
60
        return -1;
×
61
    if (add_exc(m, "DFTUtilsIndexerError", g_dft_error, &g_dft_indexer_error) <
1!
62
        0)
NEW
63
        return -1;
×
64
    if (add_exc(m, "DFTUtilsPipelineError", g_dft_error,
2!
65
                &g_dft_pipeline_error) < 0)
1✔
NEW
66
        return -1;
×
67
    if (add_exc(m, "DFTUtilsAggregationError", g_dft_error,
2!
68
                &g_dft_aggregation_error) < 0)
1✔
NEW
69
        return -1;
×
70
    return 0;
1✔
71
}
1✔
72

73
PyObject *py_error_type_for(ErrorCode code) {
1✔
74
    switch (code) {
1!
75
        case ErrorCode::INVALID_ARGUMENT:
NEW
76
            return g_dft_value_error;
×
77
        case ErrorCode::NOT_FOUND:
NEW
78
            return g_dft_not_found_error;
×
79
        case ErrorCode::IO:
80
            return g_dft_io_error;
1✔
81
        case ErrorCode::PARSE:
NEW
82
            return g_dft_parse_error;
×
83
        case ErrorCode::COMPRESSION:
NEW
84
            return g_dft_compression_error;
×
85
        case ErrorCode::QUERY:
NEW
86
            return g_dft_query_error;
×
87
        case ErrorCode::READER:
NEW
88
            return g_dft_reader_error;
×
89
        case ErrorCode::INDEXER:
NEW
90
            return g_dft_indexer_error;
×
91
        case ErrorCode::PIPELINE:
NEW
92
            return g_dft_pipeline_error;
×
93
        case ErrorCode::AGGREGATION:
NEW
94
            return g_dft_aggregation_error;
×
95
        case ErrorCode::UNKNOWN:
96
        case ErrorCode::INTERNAL:
NEW
97
            return g_dft_error;
×
98
    }
NEW
99
    return g_dft_error;
×
100
}
1✔
101

102
void set_typed_py_error(const std::exception &e) {
1✔
103
    if (const auto *de =
1!
104
            dynamic_cast<const dftracer::utils::DFTUtilsException *>(&e)) {
1!
105
        PyErr_SetString(py_error_type_for(de->code()), e.what());
1✔
106
    } else if (dynamic_cast<const std::invalid_argument *>(&e)) {
1!
NEW
107
        PyErr_SetString(g_dft_value_error, e.what());
×
NEW
108
    } else {
×
NEW
109
        PyErr_SetString(g_dft_error, e.what());
×
110
    }
111
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc