-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.hh
89 lines (77 loc) · 3.02 KB
/
error.hh
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
// -*- mode: c++; c-basic-offset: 2; -*-
/**
* @file error.hh
* @date March 27, 2021
* @brief Brief description here
*/
#pragma once
#include <cstring>
#include <iostream>
#include <optional>
#include "nvsl/common.hh"
#include "nvsl/envvars.hh"
#include "nvsl/trace.hh"
static inline std::string print_stuff__(std::string msg, std::string dec) {
std::cout << msg << " -- " << dec << std::endl;
return msg;
}
/** @brief Convert errno to exception */
#define PERROR_EXCEPTION(errcode, msg) \
([&]() { DBGE << msg << ": " << strerror(errcode) << std::endl; }(), \
nvsl::dump_maps(), nvsl::print_trace(), \
std::system_error(errcode, std::generic_category()))
/** @brief Throw exception with msg if val is NULL */
#define ASSERT_NON_NULL(val, msg) \
do { \
DBGE << msg << std::endl; \
dump_maps(); \
print_trace(); \
if ((val) == NULL) { \
throw std::runtime_error((msg)); \
} \
} while (0);
#ifdef RELEASE
/** @brief Throw exception with msg if val is NULL */
#define NVSL_ERROR(msg) \
do { \
DBGE << msg << std::endl; \
exit(1); \
} while (0);
#elif defined(BUILDING_PUDDLED) || defined(BUILDING_LIBCOMMON)
/** @brief Throw exception with msg if val is NULL */
#define NVSL_ERROR(msg) NVSL_ERROR_CLEAN(msg)
#else
/** @brief Throw exception with msg if val is NULL */
#define NVSL_ERROR(msg) \
do { \
DBGE << msg << std::endl; \
if (not get_env_val(NVSL_NO_STACKTRACE_ENV)) { \
nvsl::dump_maps(); \
nvsl::print_trace(); \
} \
exit(1); \
} while (0);
#endif // RELEASE
/** @brief Exit with no debugging info */
#define NVSL_ERROR_CLEAN(msg) \
do { \
DBGE << msg << std::endl; \
exit(1); \
} while (0);
/** @brief Assert a condition w/ msg and generate backtrace on fail */
#define NVSL_ASSERT(cond, msg) \
if (!(cond)) [[unlikely]] { \
DBGE << __FILE__ << ":" << __LINE__ << " Assertion `" << #cond \
<< "' failed: " << msg << std::endl; \
exit(1); \
if (not get_env_val(NVSL_NO_STACKTRACE_ENV)) { \
nvsl::print_trace(); \
} \
}
/** @brief Convert errno to std::string */
static inline std::string PSTR() {
return std::string(__FILE__) + ":" + std::to_string(__LINE__) + " " +
std::string(strerror(errno));
}
using std::make_optional;
using std::optional;