diff options
author | Tj Holowaychuk <tj@vision-media.ca> | 2012-01-31 04:41:32 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-01-31 10:11:19 +0400 |
commit | 26bfb6bea45348d6aaa213b4ee38ac002c429394 (patch) | |
tree | 41edb9dfbd1db831fc4f09d227bf581a9a25cf32 /src | |
parent | ff40253566089cd5b89c1e6efca32d3b5772dbcb (diff) |
more specific fs error messages
Diffstat (limited to 'src')
-rw-r--r-- | src/node_file.cc | 132 |
1 files changed, 68 insertions, 64 deletions
diff --git a/src/node_file.cc b/src/node_file.cc index abba5765dd2..fd9be59b75f 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -70,8 +70,11 @@ namespace node { using namespace v8; #define MIN(a,b) ((a) < (b) ? (a) : (b)) -#define THROW_BAD_ARGS \ - ThrowException(Exception::TypeError(String::New("Bad argument"))) + +#define TYPE_ERROR(msg) \ + ThrowException(Exception::TypeError(String::New(msg))); + +#define THROW_BAD_ARGS TYPE_ERROR("Bad argument") typedef class ReqWrap<uv_fs_t> FSReqWrap; @@ -339,9 +342,8 @@ Local<Object> BuildStatsObject(NODE_STAT_STRUCT *s) { static Handle<Value> Stat(const Arguments& args) { HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } + if (args.Length() < 1) return TYPE_ERROR("path required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); String::Utf8Value path(args[0]->ToString()); @@ -356,9 +358,8 @@ static Handle<Value> Stat(const Arguments& args) { static Handle<Value> LStat(const Arguments& args) { HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } + if (args.Length() < 1) return TYPE_ERROR("path required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); String::Utf8Value path(args[0]->ToString()); @@ -390,9 +391,11 @@ static Handle<Value> FStat(const Arguments& args) { static Handle<Value> Symlink(const Arguments& args) { HandleScope scope; - if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) { - return THROW_BAD_ARGS; - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("dest path required"); + if (len < 2) return TYPE_ERROR("src path required"); + if (!args[0]->IsString()) return TYPE_ERROR("dest path must be a string"); + if (!args[1]->IsString()) return TYPE_ERROR("src path must be a string"); String::Utf8Value dest(args[0]->ToString()); String::Utf8Value path(args[1]->ToString()); @@ -416,9 +419,11 @@ static Handle<Value> Symlink(const Arguments& args) { static Handle<Value> Link(const Arguments& args) { HandleScope scope; - if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) { - return THROW_BAD_ARGS; - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("dest path required"); + if (len < 2) return TYPE_ERROR("src path required"); + if (!args[0]->IsString()) return TYPE_ERROR("dest path must be a string"); + if (!args[1]->IsString()) return TYPE_ERROR("src path must be a string"); String::Utf8Value orig_path(args[0]->ToString()); String::Utf8Value new_path(args[1]->ToString()); @@ -434,9 +439,8 @@ static Handle<Value> Link(const Arguments& args) { static Handle<Value> ReadLink(const Arguments& args) { HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } + if (args.Length() < 1) return TYPE_ERROR("path required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); String::Utf8Value path(args[0]->ToString()); @@ -451,10 +455,12 @@ static Handle<Value> ReadLink(const Arguments& args) { static Handle<Value> Rename(const Arguments& args) { HandleScope scope; - if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) { - return THROW_BAD_ARGS; - } - + int len = args.Length(); + if (len < 1) return TYPE_ERROR("old path required"); + if (len < 2) return TYPE_ERROR("new path required"); + if (!args[0]->IsString()) return TYPE_ERROR("old path must be a string"); + if (!args[1]->IsString()) return TYPE_ERROR("new path must be a string"); + String::Utf8Value old_path(args[0]->ToString()); String::Utf8Value new_path(args[1]->ToString()); @@ -537,9 +543,8 @@ static Handle<Value> Fsync(const Arguments& args) { static Handle<Value> Unlink(const Arguments& args) { HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } + if (args.Length() < 1) return TYPE_ERROR("path required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); String::Utf8Value path(args[0]->ToString()); @@ -554,9 +559,8 @@ static Handle<Value> Unlink(const Arguments& args) { static Handle<Value> RMDir(const Arguments& args) { HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } + if (args.Length() < 1) return TYPE_ERROR("path required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); String::Utf8Value path(args[0]->ToString()); @@ -613,9 +617,8 @@ static Handle<Value> SendFile(const Arguments& args) { static Handle<Value> ReadDir(const Arguments& args) { HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } + if (args.Length() < 1) return TYPE_ERROR("path required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); String::Utf8Value path(args[0]->ToString()); @@ -647,12 +650,13 @@ static Handle<Value> ReadDir(const Arguments& args) { static Handle<Value> Open(const Arguments& args) { HandleScope scope; - if (args.Length() < 3 || - !args[0]->IsString() || - !args[1]->IsInt32() || - !args[2]->IsInt32()) { - return THROW_BAD_ARGS; - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("path required"); + if (len < 2) return TYPE_ERROR("flags required"); + if (len < 3) return TYPE_ERROR("mode required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); + if (!args[1]->IsInt32()) return TYPE_ERROR("flags must be an int"); + if (!args[2]->IsInt32()) return TYPE_ERROR("mode must be an int"); String::Utf8Value path(args[0]->ToString()); int flags = args[1]->Int32Value(); @@ -847,13 +851,13 @@ static Handle<Value> FChmod(const Arguments& args) { static Handle<Value> Chown(const Arguments& args) { HandleScope scope; - if (args.Length() < 3 || !args[0]->IsString()) { - return THROW_BAD_ARGS; - } - - if (!args[1]->IsInt32() || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("User and Group IDs must be an integer."))); - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("path required"); + if (len < 2) return TYPE_ERROR("uid required"); + if (len < 3) return TYPE_ERROR("gid required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); + if (!args[1]->IsInt32()) return TYPE_ERROR("uid must be an int"); + if (!args[2]->IsInt32()) return TYPE_ERROR("gid must be an int"); String::Utf8Value path(args[0]->ToString()); int uid = static_cast<int>(args[1]->Int32Value()); @@ -874,13 +878,13 @@ static Handle<Value> Chown(const Arguments& args) { static Handle<Value> FChown(const Arguments& args) { HandleScope scope; - if (args.Length() < 3 || !args[0]->IsInt32()) { - return THROW_BAD_ARGS; - } - - if (!args[1]->IsInt32() || !args[2]->IsInt32()) { - return ThrowException(Exception::Error(String::New("User and Group IDs must be an integer."))); - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("path required"); + if (len < 2) return TYPE_ERROR("uid required"); + if (len < 3) return TYPE_ERROR("gid required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); + if (!args[1]->IsInt32()) return TYPE_ERROR("uid must be an int"); + if (!args[2]->IsInt32()) return TYPE_ERROR("gid must be an int"); int fd = args[0]->Int32Value(); int uid = static_cast<int>(args[1]->Int32Value()); @@ -898,13 +902,13 @@ static Handle<Value> FChown(const Arguments& args) { static Handle<Value> UTimes(const Arguments& args) { HandleScope scope; - if (args.Length() < 3 - || !args[0]->IsString() - || !args[1]->IsNumber() - || !args[2]->IsNumber()) - { - return THROW_BAD_ARGS; - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("path required"); + if (len < 2) return TYPE_ERROR("atime required"); + if (len < 3) return TYPE_ERROR("mtime required"); + if (!args[0]->IsString()) return TYPE_ERROR("path must be a string"); + if (!args[1]->IsNumber()) return TYPE_ERROR("atime must be a number"); + if (!args[2]->IsNumber()) return TYPE_ERROR("mtime must be a number"); const String::Utf8Value path(args[0]->ToString()); const double atime = static_cast<double>(args[1]->NumberValue()); @@ -921,13 +925,13 @@ static Handle<Value> UTimes(const Arguments& args) { static Handle<Value> FUTimes(const Arguments& args) { HandleScope scope; - if (args.Length() < 3 - || !args[0]->IsInt32() - || !args[1]->IsNumber() - || !args[2]->IsNumber()) - { - return THROW_BAD_ARGS; - } + int len = args.Length(); + if (len < 1) return TYPE_ERROR("fd required"); + if (len < 2) return TYPE_ERROR("atime required"); + if (len < 3) return TYPE_ERROR("mtime required"); + if (!args[0]->IsInt32()) return TYPE_ERROR("fd must be an int"); + if (!args[1]->IsNumber()) return TYPE_ERROR("atime must be a number"); + if (!args[2]->IsNumber()) return TYPE_ERROR("mtime must be a number"); const int fd = args[0]->Int32Value(); const double atime = static_cast<double>(args[1]->NumberValue()); |