Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit 13c4591

Browse files
committed
Merge branch 'kpdecker-path-error'
2 parents 7e8a7db + add2bae commit 13c4591

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lib/MemoryFileSystem.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function isFile(item) {
2020
function pathToArray(path) {
2121
var nix = /^\//.test(path);
2222
if(!nix) {
23-
if(!/^[A-Za-z]:/.test(path)) throw new Error("Invalid path " + path);
23+
if(!/^[A-Za-z]:/.test(path)) throw new Error("Invalid path '" + path + "'");
2424
path = path.replace(/[\\\/]+/g, "\\"); // multi slashs
2525
path = path.split(/[\\\/]/);
2626
path[0] = path[0].toUpperCase();
@@ -32,15 +32,15 @@ function pathToArray(path) {
3232
return path;
3333
}
3434

35-
function trueFn() { return true }
36-
function falseFn() { return false }
35+
function trueFn() { return true; }
36+
function falseFn() { return false; }
3737

3838
MemoryFileSystem.prototype.statSync = function(_path) {
3939
var path = pathToArray(_path);
4040
var current = this.data;
4141
for(var i = 0; i < path.length - 1; i++) {
4242
if(!isDir(current[path[i]]))
43-
throw new Error("Path doesn't exist " + _path);
43+
throw new Error("Path doesn't exist '" + _path + "'");
4444
current = current[path[i]];
4545
}
4646
if(_path === "/" || isDir(current[path[i]])) {
@@ -64,22 +64,22 @@ MemoryFileSystem.prototype.statSync = function(_path) {
6464
isSocket: falseFn
6565
};
6666
} else
67-
throw new Error("Path doesn't exist " + _path);
67+
throw new Error("Path doesn't exist '" + _path + "'");
6868
};
6969

7070
MemoryFileSystem.prototype.readFileSync = function(_path, encoding) {
7171
var path = pathToArray(_path);
7272
var current = this.data;
7373
for(var i = 0; i < path.length - 1; i++) {
7474
if(!isDir(current[path[i]]))
75-
throw new Error("Path doesn't exist " + _path);
75+
throw new Error("Path doesn't exist '" + _path + "'");
7676
current = current[path[i]];
7777
}
7878
if(!isFile(current[path[i]])) {
7979
if(isDir(current[path[i]]))
80-
throw new Error("Cannot readFile on directory " + _path);
80+
throw new Error("Cannot readFile on directory '" + _path + "'");
8181
else
82-
throw new Error("File doesn't exist " + _path);
82+
throw new Error("Path doesn't exist '" + _path + "'");
8383
}
8484
current = current[path[i]];
8585
return encoding ? current.toString(encoding) : current;
@@ -91,14 +91,14 @@ MemoryFileSystem.prototype.readdirSync = function(_path) {
9191
var current = this.data;
9292
for(var i = 0; i < path.length - 1; i++) {
9393
if(!isDir(current[path[i]]))
94-
throw new Error("Path doesn't exist " + _path);
94+
throw new Error("Path doesn't exist '" + _path + "'");
9595
current = current[path[i]];
9696
}
9797
if(!isDir(current[path[i]])) {
9898
if(isFile(current[path[i]]))
99-
throw new Error("Cannot readdir on file " + _path);
99+
throw new Error("Cannot readdir on file '" + _path + "'");
100100
else
101-
throw new Error("File doesn't exist " + _path);
101+
throw new Error("Path doesn't exist '" + _path + "'");
102102
}
103103
return Object.keys(current[path[i]]).filter(Boolean);
104104
};
@@ -109,7 +109,7 @@ MemoryFileSystem.prototype.mkdirpSync = function(_path) {
109109
var current = this.data;
110110
for(var i = 0; i < path.length; i++) {
111111
if(isFile(current[path[i]]))
112-
throw new Error("Path is a file " + _path);
112+
throw new Error("Path is a file '" + _path + "'");
113113
else if(!isDir(current[path[i]]))
114114
current[path[i]] = {"":true};
115115
current = current[path[i]];
@@ -123,28 +123,28 @@ MemoryFileSystem.prototype.mkdirSync = function(_path) {
123123
var current = this.data;
124124
for(var i = 0; i < path.length - 1; i++) {
125125
if(!isDir(current[path[i]]))
126-
throw new Error("Path doesn't exist " + _path);
126+
throw new Error("Path doesn't exist '" + _path + "'");
127127
current = current[path[i]];
128128
}
129129
if(isDir(current[path[i]]))
130-
throw new new Error("Directory already exist " + _path);
130+
throw new new Error("Directory already exist '" + _path + "'");
131131
else if(isFile(current[path[i]]))
132-
throw new Error("Cannot mkdir on file " + _path);
132+
throw new Error("Cannot mkdir on file '" + _path + "'");
133133
current[path[i]] = {"":true};
134134
return;
135135
};
136136

137137
MemoryFileSystem.prototype._remove = function(_path, name, testFn) {
138138
var path = pathToArray(_path);
139-
if(path.length === 0) throw new Error("Path cannot be removed " + _path);
139+
if(path.length === 0) throw new Error("Path cannot be removed '" + _path + "'");
140140
var current = this.data;
141141
for(var i = 0; i < path.length - 1; i++) {
142142
if(!isDir(current[path[i]]))
143-
throw new Error("Path doesn't exist " + _path);
143+
throw new Error("Path doesn't exist '" + _path + "'");
144144
current = current[path[i]];
145145
}
146146
if(!testFn(current[path[i]]))
147-
throw new Error(name + " doesn't exist " + _path);
147+
throw new Error("'" + name + "' doesn't exist '" + _path + "'");
148148
delete current[path[i]];
149149
return;
150150
};
@@ -160,15 +160,15 @@ MemoryFileSystem.prototype.unlinkSync = function(_path) {
160160
MemoryFileSystem.prototype.writeFileSync = function(_path, content, encoding) {
161161
if(!content && !encoding) throw new Error("No content");
162162
var path = pathToArray(_path);
163-
if(path.length === 0) throw new Error("Path is not a file " + _path);
163+
if(path.length === 0) throw new Error("Path is not a file '" + _path + "'");
164164
var current = this.data;
165165
for(var i = 0; i < path.length - 1; i++) {
166166
if(!isDir(current[path[i]]))
167-
throw new Error("Path doesn't exist " + _path);
167+
throw new Error("Path doesn't exist '" + _path + "'");
168168
current = current[path[i]];
169169
}
170170
if(isDir(current[path[i]]))
171-
throw new Error("Cannot writeFile on directory " + _path);
171+
throw new Error("Cannot writeFile on directory '" + _path + "'");
172172
current[path[i]] = encoding || typeof content === "string" ? new Buffer(content, encoding) : content;
173173
return;
174174
};

0 commit comments

Comments
 (0)