Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ static Napi::Object getDiskUsage(const Napi::CallbackInfo& info) {

Napi::String path = info[0].As<Napi::String>();
std::string pathText = path;

DiskUsage usage = GetDiskUsage(pathText.c_str());

DiskUsage usage = {};
try {
usage = GetDiskUsage(pathText.c_str());
} catch (const std::runtime_error& e) {
throw Napi::Error::New(env, std::string("GetDiskUsage failed: ") + e.what());
} catch (const SystemError& e) {
std::string errorMessage = "SystemError: " + e.message() + " (syscall: " + e.syscall() + ", errno: " + std::to_string(e.errorno()) + ", path: " + e.path() + ")";
throw Napi::Error::New(env, errorMessage);
} catch (...) {
throw Napi::Error::New(env, "An unknown error occurred while getting disk usage");
}

Napi::Object result = Napi::Object::New(env);
result.Set("available", Napi::Number::New(env, static_cast<double>(usage.available)));
Expand Down