Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* This file is part of the CernVM File System. |
3 |
|
|
*/ |
4 |
|
|
|
5 |
|
|
#ifndef CVMFS_UTIL_EXCEPTION_H_ |
6 |
|
|
#define CVMFS_UTIL_EXCEPTION_H_ |
7 |
|
|
|
8 |
|
|
#include <cassert> |
9 |
|
|
#include <cstdarg> |
10 |
|
|
#include <stdexcept> |
11 |
|
|
#include <string> |
12 |
|
|
|
13 |
|
|
#include "util/export.h" |
14 |
|
|
#include "util/logging.h" |
15 |
|
|
|
16 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
17 |
|
|
namespace CVMFS_NAMESPACE_GUARD { |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
class CVMFS_EXPORT ECvmfsException : public std::runtime_error { |
21 |
|
|
public: |
22 |
|
19 |
explicit ECvmfsException(const std::string& what_arg) |
23 |
|
19 |
: std::runtime_error(what_arg) {} |
24 |
|
|
}; |
25 |
|
|
|
26 |
|
|
#define CVMFS_S1(x) #x |
27 |
|
|
#define CVMFS_S2(x) CVMFS_S1(x) |
28 |
|
|
#define CVMFS_SOURCE_LOCATION "PANIC: " __FILE__ " : " CVMFS_S2(__LINE__) |
29 |
|
|
#define PANIC(...) Panic(CVMFS_SOURCE_LOCATION, kLogCvmfs, __VA_ARGS__); |
30 |
|
|
|
31 |
|
|
CVMFS_EXPORT |
32 |
|
|
__attribute__((noreturn)) |
33 |
|
|
void Panic(const char *coordinates, const LogSource source, const int mask, |
34 |
|
|
const char *format, ...); |
35 |
|
|
|
36 |
|
|
// For PANIC(NULL) |
37 |
|
|
CVMFS_EXPORT |
38 |
|
|
__attribute__((noreturn)) |
39 |
|
|
void Panic(const char *coordinates, const LogSource source, const char *nul); |
40 |
|
|
|
41 |
|
|
// The AssertOrLog function is used for rare error cases that are not yet fully |
42 |
|
|
// understood. By default, these error cases are considered as unreachable and |
43 |
|
|
// thus an assert is thrown. Some users may prefer though to continue operation |
44 |
|
|
// (even though the file system state may be scrambled). |
45 |
|
|
// Ideally, we can at some point remove all AssertOrLog statements. |
46 |
|
|
#ifdef CVMFS_SUPPRESS_ASSERTS |
47 |
|
|
static inline bool AssertOrLog(int t, |
48 |
|
|
const LogSource log_source, |
49 |
|
|
const int log_mask, |
50 |
|
|
const char *log_msg_format, ...) { |
51 |
|
|
if (!t) { |
52 |
|
|
va_list variadic_list; |
53 |
|
|
va_start(variadic_list, log_msg_format); |
54 |
|
|
vLogCvmfs(log_source, log_mask, log_msg_format, variadic_list); |
55 |
|
|
va_end(variadic_list); |
56 |
|
|
return false; |
57 |
|
|
} |
58 |
|
|
return true; |
59 |
|
|
} |
60 |
|
|
#else |
61 |
|
16 |
static inline bool AssertOrLog(int t, |
62 |
|
|
const LogSource /*log_source*/, |
63 |
|
|
const int /*log_mask*/, |
64 |
|
|
const char* /*log_msg_format*/, ...) { |
65 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
|
16 |
assert(t); |
66 |
|
16 |
return true; |
67 |
|
|
} |
68 |
|
|
#endif |
69 |
|
|
|
70 |
|
|
#ifdef CVMFS_NAMESPACE_GUARD |
71 |
|
|
} // namespace CVMFS_NAMESPACE_GUARD |
72 |
|
|
#endif |
73 |
|
|
|
74 |
|
|
#endif // CVMFS_UTIL_EXCEPTION_H_ |
75 |
|
|
|