@ -698,11 +698,10 @@ void ThrowUVException(v8::Isolate* isolate,
int errorno ,
int errorno ,
const char * syscall ,
const char * syscall ,
const char * message ,
const char * message ,
const char * path ) {
const char * path ,
Environment : : GetCurrent ( isolate ) - > ThrowErrnoException ( errorno ,
const char * dest ) {
syscall ,
Environment : : GetCurrent ( isolate )
message ,
- > ThrowUVException ( errorno , syscall , message , path , dest ) ;
path ) ;
}
}
@ -752,64 +751,78 @@ Local<Value> ErrnoException(Isolate* isolate,
}
}
// hack alert! copy of ErrnoException, tuned for uv errors
static Local < String > StringFromPath ( Isolate * isolate , const char * path ) {
# ifdef _WIN32
if ( strncmp ( path , " \\ \\ ? \\ UNC \\ " , 8 ) = = 0 ) {
return String : : Concat ( FIXED_ONE_BYTE_STRING ( isolate , " \\ \\ " ) ,
String : : NewFromUtf8 ( isolate , path + 8 ) ) ;
} else if ( strncmp ( path , " \\ \\ ? \\ " , 4 ) = = 0 ) {
return String : : NewFromUtf8 ( isolate , path + 4 ) ;
}
# endif
return String : : NewFromUtf8 ( isolate , path ) ;
}
Local < Value > UVException ( Isolate * isolate ,
int errorno ,
const char * syscall ,
const char * msg ,
const char * path ) {
return UVException ( isolate , errorno , syscall , msg , path , nullptr ) ;
}
Local < Value > UVException ( Isolate * isolate ,
Local < Value > UVException ( Isolate * isolate ,
int errorno ,
int errorno ,
const char * syscall ,
const char * syscall ,
const char * msg ,
const char * msg ,
const char * path ) {
const char * path ,
const char * dest ) {
Environment * env = Environment : : GetCurrent ( isolate ) ;
Environment * env = Environment : : GetCurrent ( isolate ) ;
if ( ! msg | | ! msg [ 0 ] )
if ( ! msg | | ! msg [ 0 ] )
msg = uv_strerror ( errorno ) ;
msg = uv_strerror ( errorno ) ;
Local < String > estring = OneByteString ( env - > isolate ( ) , uv_err_name ( errorno ) ) ;
Local < String > js_code = OneByteString ( isolate , uv_err_name ( errorno ) ) ;
Local < String > message = OneByteString ( env - > isolate ( ) , msg ) ;
Local < String > js_syscall = OneByteString ( isolate , syscall ) ;
Local < String > cons1 =
Local < String > js_path ;
String : : Concat ( estring , FIXED_ONE_BYTE_STRING ( env - > isolate ( ) , " , " ) ) ;
Local < String > js_dest ;
Local < String > cons2 = String : : Concat ( cons1 , message ) ;
Local < Value > e ;
Local < String > path_str ;
Local < String > js_msg = js_code ;
js_msg = String : : Concat ( js_msg , FIXED_ONE_BYTE_STRING ( isolate , " : " ) ) ;
js_msg = String : : Concat ( js_msg , OneByteString ( isolate , msg ) ) ;
js_msg = String : : Concat ( js_msg , FIXED_ONE_BYTE_STRING ( isolate , " , " ) ) ;
js_msg = String : : Concat ( js_msg , js_syscall ) ;
if ( path ) {
if ( path ! = nullptr ) {
# ifdef _WIN32
js_path = StringFromPath ( isolate , path ) ;
if ( strncmp ( path , " \\ \\ ? \\ UNC \\ " , 8 ) = = 0 ) {
path_str = String : : Concat ( FIXED_ONE_BYTE_STRING ( env - > isolate ( ) , " \\ \\ " ) ,
String : : NewFromUtf8 ( env - > isolate ( ) , path + 8 ) ) ;
} else if ( strncmp ( path , " \\ \\ ? \\ " , 4 ) = = 0 ) {
path_str = String : : NewFromUtf8 ( env - > isolate ( ) , path + 4 ) ;
} else {
path_str = String : : NewFromUtf8 ( env - > isolate ( ) , path ) ;
}
# else
path_str = String : : NewFromUtf8 ( env - > isolate ( ) , path ) ;
# endif
Local < String > cons3 =
js_msg = String : : Concat ( js_msg , FIXED_ONE_BYTE_STRING ( isolate , " ' " ) ) ;
String : : Concat ( cons2 , FIXED_ONE_BYTE_STRING ( env - > isolate ( ) , " ' " ) ) ;
js_msg = String : : Concat ( js_msg , js_path ) ;
Local < String > cons4 =
js_msg = String : : Concat ( js_msg , FIXED_ONE_BYTE_STRING ( isolate , " ' " ) ) ;
String : : Concat ( cons3 , path_str ) ;
Local < String > cons5 =
String : : Concat ( cons4 , FIXED_ONE_BYTE_STRING ( env - > isolate ( ) , " ' " ) ) ;
e = Exception : : Error ( cons5 ) ;
} else {
e = Exception : : Error ( cons2 ) ;
}
}
Local < Object > obj = e - > ToObject ( env - > isolate ( ) ) ;
if ( dest ! = nullptr ) {
// TODO(piscisaureus) errno should probably go
js_dest = StringFromPath ( isolate , dest ) ;
obj - > Set ( env - > errno_string ( ) , Integer : : New ( env - > isolate ( ) , errorno ) ) ;
obj - > Set ( env - > code_string ( ) , estring ) ;
if ( path ! = nullptr ) {
js_msg = String : : Concat ( js_msg , FIXED_ONE_BYTE_STRING ( isolate , " -> ' " ) ) ;
obj - > Set ( env - > path_string ( ) , path_str ) ;
js_msg = String : : Concat ( js_msg , js_dest ) ;
js_msg = String : : Concat ( js_msg , FIXED_ONE_BYTE_STRING ( isolate , " ' " ) ) ;
}
}
if ( syscall ! = nullptr ) {
Local < Object > e = Exception : : Error ( js_msg ) - > ToObject ( isolate ) ;
obj - > Set ( env - > syscall_string ( ) , OneByteString ( env - > isolate ( ) , syscall ) ) ;
}
// TODO(piscisaureus) errno should probably go; the user has no way of
// knowing which uv errno value maps to which error.
e - > Set ( env - > errno_string ( ) , Integer : : New ( isolate , errorno ) ) ;
e - > Set ( env - > code_string ( ) , js_code ) ;
e - > Set ( env - > syscall_string ( ) , js_syscall ) ;
if ( ! js_path . IsEmpty ( ) )
e - > Set ( env - > path_string ( ) , js_path ) ;
if ( ! js_dest . IsEmpty ( ) )
e - > Set ( env - > dest_string ( ) , js_dest ) ;
return e ;
return e ;
}
}