Created
August 16, 2011 03:27
-
-
Save tshinnic/1148378 to your computer and use it in GitHub Desktop.
Possible elaboration on errnoException() for node 0.5.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//XXX Maybe someday there will be a nice way for user-land modules to | |
// generate pseudo-errno errors? | |
function errnoException(errno, syscall, message, path) { | |
var e = new Error(); | |
var msg = ''; | |
if ( syscall !== undefined ) { | |
msg += syscall + ' '; | |
e.syscall = syscall; | |
} | |
if ( errno !== undefined ) { | |
// Try to resolve errno to both a name and a value | |
if ( typeof errno === 'string' && isOwn.call(constants, errno) ) { | |
e.code = errno; | |
e.errno = constants[errno]; | |
msg += errno; | |
} else { | |
e.code = e.errno = errno; | |
msg += errno.toString(); | |
} | |
} | |
if ( message !== undefined ) { | |
if ( msg !== '' ) { msg += ', '; } | |
msg += message; | |
} | |
if ( path !== undefined ) { | |
if ( msg !== '' ) { msg += ' '; } | |
msg += '\'' + path + '\''; | |
e.path = path; | |
} | |
e.message = msg; | |
return e; | |
} | |
Saw real exception object true (instanceof Error) | |
{ stack: [Getter/Setter], | |
arguments: undefined, | |
type: undefined, | |
message: 'ELOOP, Too many levels of symbolic links \'/home/Tom/study/javascript/node.js/play/test/tmp/testrpx/realpath-3a\'', | |
errno: 40, | |
code: 'ELOOP', | |
path: '/home/Tom/study/javascript/node.js/play/test/tmp/testrpx/realpath-3a' } | |
Saw fake exception object true (instanceof Error) | |
{ stack: [Getter/Setter], | |
arguments: undefined, | |
type: undefined, | |
code: 'ELOOP', | |
errno: 40, | |
path: '/home/Tom/study/javascript/node.js/play/test/tmp/testrpx/realpath-3a', | |
message: 'ELOOP, Too many levels of symbolic links \'/home/Tom/study/javascript/node.js/play/test/tmp/testrpx/realpath-3a\'' } | |
Throwing the 'real' exception | |
node.js:134 | |
throw e; // process.nextTick error, or 'error' event on first tick | |
^ | |
Error: ELOOP, Too many levels of symbolic links '/home/Tom/study/javascript/node.js/play/test/tmp/testrpx/realpath-3a' | |
at Object.statSync (fs.js:400:18) | |
at realpathX (/home/Tom/study/javascript/node.js/play/pathroot.js:408:18) | |
at test_cyclic_link | |
Throwing the 'fake' exception | |
node.js:134 | |
throw e; // process.nextTick error, or 'error' event on first tick | |
^ | |
Error: ELOOP, Too many levels of symbolic links '/home/Tom/study/javascript/node.js/play/test/tmp/testrpx/realpath-3a' | |
at errnoException (/home/Tom/study/javascript/node.js/play/pathroot.js:51:11) | |
at realpathX (/home/Tom/study/javascript/node.js/play/pathroot.js:395:21) | |
at test_cyclic_link_protection (/home/Tom/study/javascript/node.js/play/test/test_realpathx02.js:281:12) | |
lt(' Saw real exception ', typeof ex, ex instanceof Error); | |
lt(ex); | |
var exx = errnoException('ELOOP', undefined, | |
'Too many levels of symbolic links', base); | |
lt(' Saw fake exception ', typeof exx, exx instanceof Error); | |
lt(exx); | |
throw exx; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whoops, isOwn() is