Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
validate the input and throw a predictable error if unsatisfied
Browse files Browse the repository at this point in the history
Co-Authored-By: Brian Anglin <@thebriananglin>
  • Loading branch information
shiftkey committed May 24, 2019
1 parent 794a539 commit 2755cba
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/main.cc
Expand Up @@ -4,10 +4,27 @@
namespace {

NAN_METHOD(SetPassword) {
if (!info[0]->IsString()) {
Nan::ThrowTypeError("Parameter 'service' must be a string");
return;
}

Nan::Utf8String serviceNan(info[0]);
std::string service(*serviceNan, serviceNan.length());

if (!info[1]->IsString()) {
Nan::ThrowTypeError("Parameter 'username' must be a string");
return;
}

Nan::Utf8String usernameNan(info[1]);
std::string username(*usernameNan, usernameNan.length());

if (!info[2]->IsString()) {
Nan::ThrowTypeError("Parameter 'password' must be a string");
return;
}

Nan::Utf8String passwordNan(info[2]);
std::string password(*passwordNan, passwordNan.length());

Expand All @@ -20,8 +37,19 @@ NAN_METHOD(SetPassword) {
}

NAN_METHOD(GetPassword) {
if (!info[0]->IsString()) {
Nan::ThrowTypeError("Parameter 'service' must be a string");
return;
}

Nan::Utf8String serviceNan(info[0]);
std::string service(*serviceNan, serviceNan.length());

if (!info[1]->IsString()) {
Nan::ThrowTypeError("Parameter 'username' must be a string");
return;
}

Nan::Utf8String usernameNan(info[1]);
std::string username(*usernameNan, usernameNan.length());

Expand All @@ -33,8 +61,19 @@ NAN_METHOD(GetPassword) {
}

NAN_METHOD(DeletePassword) {
if (!info[0]->IsString()) {
Nan::ThrowTypeError("Parameter 'service' must be a string");
return;
}

Nan::Utf8String serviceNan(info[0]);
std::string service(*serviceNan, serviceNan.length());

if (!info[1]->IsString()) {
Nan::ThrowTypeError("Parameter 'username' must be a string");
return;
}

Nan::Utf8String usernameNan(info[1]);
std::string username(*usernameNan, usernameNan.length());

Expand All @@ -46,6 +85,11 @@ NAN_METHOD(DeletePassword) {
}

NAN_METHOD(FindPassword) {
if (!info[0]->IsString()) {
Nan::ThrowTypeError("Parameter 'service' must be a string");
return;
}

Nan::Utf8String serviceNan(info[0]);
std::string service(*serviceNan, serviceNan.length());

Expand All @@ -56,6 +100,11 @@ NAN_METHOD(FindPassword) {
}

NAN_METHOD(FindCredentials) {
if (!info[0]->IsString()) {
Nan::ThrowTypeError("Parameter 'service' must be a string");
return;
}

Nan::Utf8String serviceNan(info[0]);
std::string service(*serviceNan, serviceNan.length());

Expand Down

0 comments on commit 2755cba

Please sign in to comment.