forked from Automattic/node-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanvasError.h
More file actions
37 lines (35 loc) · 977 Bytes
/
CanvasError.h
File metadata and controls
37 lines (35 loc) · 977 Bytes
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
#pragma once
#include <string>
#include <napi.h>
class CanvasError {
public:
std::string message;
std::string syscall;
std::string path;
int cerrno = 0;
void set(const char* iMessage = NULL, const char* iSyscall = NULL, int iErrno = 0, const char* iPath = NULL) {
if (iMessage) message.assign(iMessage);
if (iSyscall) syscall.assign(iSyscall);
cerrno = iErrno;
if (iPath) path.assign(iPath);
}
void reset() {
message.clear();
syscall.clear();
path.clear();
cerrno = 0;
}
bool empty() {
return cerrno == 0 && message.empty();
}
Napi::Error toError(Napi::Env env) {
if (cerrno) {
Napi::Error err = Napi::Error::New(env, strerror(cerrno));
if (!syscall.empty()) err.Value().Set("syscall", syscall);
if (!path.empty()) err.Value().Set("path", path);
return err;
} else {
return Napi::Error::New(env, message);
}
}
};