-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy patherror.cc
50 lines (41 loc) · 1.22 KB
/
error.cc
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
#include <cstdarg>
#include "error.h"
namespace llnode {
bool Error::is_debug_mode = false;
Error::Error(bool failed, const char* format, ...) {
failed_ = failed;
char tmp[kMaxMessageLength];
va_list arglist;
va_start(arglist, format);
vsnprintf(tmp, sizeof(tmp), format, arglist);
va_end(arglist);
msg_ = tmp;
}
void Error::PrintInDebugMode(const char* file, int line, const char* funcname,
const char* format, ...) {
if (!is_debug_mode) {
return;
}
char fmt[kMaxMessageLength];
snprintf(fmt, sizeof(fmt), "[llnode][%s %s:%d] %s\n", funcname, file, line,
format);
va_list arglist;
va_start(arglist, format);
vfprintf(stderr, fmt, arglist);
va_end(arglist);
}
Error Error::Failure(std::string msg) {
// TODO(mmarchini): The file and function information here won't be relevant.
// But then again, maybe we should rethink Error::Failure.
PRINT_DEBUG("%s", msg.c_str());
return Error(true, msg);
}
Error Error::Failure(const char* format, ...) {
char tmp[kMaxMessageLength];
va_list arglist;
va_start(arglist, format);
vsnprintf(tmp, sizeof(tmp), format, arglist);
va_end(arglist);
return Error::Failure(std::string(tmp));
}
} // namespace llnode