Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more specific fs error messages

  • Loading branch information...
commit 26bfb6bea45348d6aaa213b4ee38ac002c429394 1 parent ff40253
@tj tj authored isaacs committed
Showing with 68 additions and 64 deletions.
  1. +68 −64 src/node_file.cc
View
132 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());

0 comments on commit 26bfb6b

Please sign in to comment.
Something went wrong with that request. Please try again.