Skip to content

Commit 823a443

Browse files
piscisaureusBert Belder
authored and
Bert Belder
committed
Rename FSError to UVException and move to node.cc
1 parent 1ad30a2 commit 823a443

File tree

3 files changed

+88
-87
lines changed

3 files changed

+88
-87
lines changed

src/node.cc

+76
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,82 @@ Local<Value> ErrnoException(int errorno,
800800
}
801801

802802

803+
static const char* get_uv_errno_string(int errorno) {
804+
uv_err_t err;
805+
memset(&err, 0, sizeof err);
806+
err.code = (uv_err_code)errorno;
807+
return uv_err_name(err);
808+
}
809+
810+
811+
static const char* get_uv_errno_message(int errorno) {
812+
uv_err_t err;
813+
memset(&err, 0, sizeof err);
814+
err.code = (uv_err_code)errorno;
815+
return uv_strerror(err);
816+
}
817+
818+
819+
// hack alert! copy of ErrnoException, tuned for uv errors
820+
Local<Value> UVException(int errorno,
821+
const char *syscall,
822+
const char *msg,
823+
const char *path) {
824+
static Persistent<String> syscall_symbol;
825+
static Persistent<String> errpath_symbol;
826+
static Persistent<String> code_symbol;
827+
828+
if (syscall_symbol.IsEmpty()) {
829+
syscall_symbol = NODE_PSYMBOL("syscall");
830+
errno_symbol = NODE_PSYMBOL("errno");
831+
errpath_symbol = NODE_PSYMBOL("path");
832+
code_symbol = NODE_PSYMBOL("code");
833+
}
834+
835+
if (!msg || !msg[0])
836+
msg = get_uv_errno_message(errorno);
837+
838+
Local<String> estring = String::NewSymbol(errno_string(errorno));
839+
Local<String> message = String::NewSymbol(msg);
840+
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
841+
Local<String> cons2 = String::Concat(cons1, message);
842+
843+
Local<Value> e;
844+
845+
Local<String> path_str;
846+
847+
if (path) {
848+
#ifdef _WIN32
849+
if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
850+
path_str = String::Concat(String::New("\\\\"), String::New(path + 8));
851+
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
852+
path_str = String::New(path + 4);
853+
} else {
854+
path_str = String::New(path);
855+
}
856+
#else
857+
path_str = String::New(path);
858+
#endif
859+
860+
Local<String> cons3 = String::Concat(cons2, String::NewSymbol(" '"));
861+
Local<String> cons4 = String::Concat(cons3, path_str);
862+
Local<String> cons5 = String::Concat(cons4, String::NewSymbol("'"));
863+
e = Exception::Error(cons5);
864+
} else {
865+
e = Exception::Error(cons2);
866+
}
867+
868+
Local<Object> obj = e->ToObject();
869+
870+
// TODO errno should probably go
871+
obj->Set(errno_symbol, Integer::New(errorno));
872+
obj->Set(code_symbol, estring);
873+
if (path) obj->Set(errpath_symbol, path_str);
874+
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
875+
return e;
876+
}
877+
878+
803879
#ifdef _WIN32
804880
Local<Value> WinapiErrnoException(int errorno,
805881
const char* syscall,

src/node.h

+6
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ NODE_EXTERN v8::Local<v8::Value> ErrnoException(int errorno,
192192
const char *syscall = NULL,
193193
const char *msg = "",
194194
const char *path = NULL);
195+
196+
NODE_EXTERN v8::Local<v8::Value> UVException(int errorno,
197+
const char *syscall = NULL,
198+
const char *msg = NULL,
199+
const char *path = NULL);
200+
195201
#ifdef _WIN32
196202
NODE_EXTERN v8::Local<v8::Value> WinapiErrnoException(int errorno,
197203
const char *syscall = NULL, const char *msg = "",

src/node_file.cc

+6-87
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ static Persistent<String> errno_symbol;
5656
static Persistent<String> buf_symbol;
5757
static Persistent<String> oncomplete_sym;
5858

59-
Local<Value> FSError(int errorno,
60-
const char *syscall = NULL,
61-
const char *msg = NULL,
62-
const char *path = NULL);
63-
6459

6560
#ifdef _LARGEFILE_SOURCE
6661
static inline int IsInt64(double x) {
@@ -91,12 +86,12 @@ static void After(uv_fs_t *req) {
9186
// If the request doesn't have a path parameter set.
9287

9388
if (!req->path) {
94-
argv[0] = FSError(req->errorno);
89+
argv[0] = UVException(req->errorno);
9590
} else {
96-
argv[0] = FSError(req->errorno,
97-
NULL,
98-
NULL,
99-
static_cast<const char*>(req->path));
91+
argv[0] = UVException(req->errorno,
92+
NULL,
93+
NULL,
94+
static_cast<const char*>(req->path));
10095
}
10196
} else {
10297
// error value is empty or null for non-error.
@@ -210,82 +205,6 @@ struct fs_req_wrap {
210205
};
211206

212207

213-
const char* errno_string(int errorno) {
214-
uv_err_t err;
215-
memset(&err, 0, sizeof err);
216-
err.code = (uv_err_code)errorno;
217-
return uv_err_name(err);
218-
}
219-
220-
221-
const char* errno_message(int errorno) {
222-
uv_err_t err;
223-
memset(&err, 0, sizeof err);
224-
err.code = (uv_err_code)errorno;
225-
return uv_strerror(err);
226-
}
227-
228-
229-
// hack alert! copy of ErrnoException in node.cc, tuned for uv errors
230-
Local<Value> FSError(int errorno,
231-
const char *syscall,
232-
const char *msg,
233-
const char *path) {
234-
static Persistent<String> syscall_symbol;
235-
static Persistent<String> errpath_symbol;
236-
static Persistent<String> code_symbol;
237-
238-
if (syscall_symbol.IsEmpty()) {
239-
syscall_symbol = NODE_PSYMBOL("syscall");
240-
errno_symbol = NODE_PSYMBOL("errno");
241-
errpath_symbol = NODE_PSYMBOL("path");
242-
code_symbol = NODE_PSYMBOL("code");
243-
}
244-
245-
if (!msg || !msg[0])
246-
msg = errno_message(errorno);
247-
248-
Local<String> estring = String::NewSymbol(errno_string(errorno));
249-
Local<String> message = String::NewSymbol(msg);
250-
Local<String> cons1 = String::Concat(estring, String::NewSymbol(", "));
251-
Local<String> cons2 = String::Concat(cons1, message);
252-
253-
Local<Value> e;
254-
255-
Local<String> path_str;
256-
257-
if (path) {
258-
#ifdef _WIN32
259-
if (strncmp(path, "\\\\?\\UNC\\", 8) == 0) {
260-
path_str = String::Concat(String::New("\\\\"), String::New(path + 8));
261-
} else if (strncmp(path, "\\\\?\\", 4) == 0) {
262-
path_str = String::New(path + 4);
263-
} else {
264-
path_str = String::New(path);
265-
}
266-
#else
267-
path_str = String::New(path);
268-
#endif
269-
270-
Local<String> cons3 = String::Concat(cons2, String::NewSymbol(" '"));
271-
Local<String> cons4 = String::Concat(cons3, path_str);
272-
Local<String> cons5 = String::Concat(cons4, String::NewSymbol("'"));
273-
e = Exception::Error(cons5);
274-
} else {
275-
e = Exception::Error(cons2);
276-
}
277-
278-
Local<Object> obj = e->ToObject();
279-
280-
// TODO errno should probably go
281-
obj->Set(errno_symbol, Integer::New(errorno));
282-
obj->Set(code_symbol, estring);
283-
if (path) obj->Set(errpath_symbol, path_str);
284-
if (syscall) obj->Set(syscall_symbol, String::NewSymbol(syscall));
285-
return e;
286-
}
287-
288-
289208
#define ASYNC_CALL(func, callback, ...) \
290209
FSReqWrap* req_wrap = new FSReqWrap(); \
291210
int r = uv_fs_##func(uv_default_loop(), &req_wrap->req_, \
@@ -300,7 +219,7 @@ Local<Value> FSError(int errorno,
300219
int result = uv_fs_##func(uv_default_loop(), &req_wrap.req, __VA_ARGS__, NULL); \
301220
if (result < 0) { \
302221
int code = uv_last_error(uv_default_loop()).code; \
303-
return ThrowException(FSError(code, #func, "", path)); \
222+
return ThrowException(UVException(code, #func, "", path)); \
304223
}
305224

306225
#define SYNC_REQ req_wrap.req

0 commit comments

Comments
 (0)