Permalink
Browse files

Set error code on exceptions

  • Loading branch information...
1 parent 8febf2f commit 51b3794036b23686b365be60517763773ef11938 @vojtajina committed Jun 25, 2012
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/fs.js
View
@@ -93,17 +93,24 @@ var Mock = function(structure) {
this.readFileSync = function(path) {
var pointer = getPointer(path, structure);
+ var error;
if (!pointer) {
- throw new Error(util.format('No such file or directory "%s"', path));
+ error = new Error(util.format('No such file or directory "%s"', path));
+ error.code = 'ENOENT';
+
+ throw error;
}
if (pointer instanceof File) {
return pointer.getBuffer();
}
if (typeof pointer === 'object') {
- throw new Error('Illegal operation on directory');
+ error = new Error('Illegal operation on directory');
+ error.code = 'EISDIR';
+
+ throw error;
}
return new Buffer('');

0 comments on commit 51b3794

Please sign in to comment.