Files
med-notes/.pnpm-store/v10/files/85/fc26c2e64eebd3ec59674b0727ff4fc1dc4b166be4f9902f0c48e70bb5b43045b67a378e527033b43beb54b3568cb62193969224936270b567064f8079e374
2025-05-09 05:30:08 +02:00

38 lines
977 B
Plaintext

#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);
}
}
};