Skip to content

Commit 61183d5

Browse files
docs: add/modify the Error msg, correct the jsdoc of .filename()
1 parent 1fe0791 commit 61183d5

File tree

7 files changed

+62
-58
lines changed

7 files changed

+62
-58
lines changed

src/core/fs/copy.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ export async function copy(
7171
const { 0: srcStat, 1: destStat } = await getStats(src, dest, options);
7272
if (destStat) {
7373
if (areIdentical(srcStat, destStat)) {
74-
throw new Error(`[path-nice] copy(): src and dest cannot be the same`);
74+
throw new Error(`[path-nice] .copy(): src and dest cannot be the same`);
7575
}
7676
if (srcStat.isDirectory() && !destStat.isDirectory()) {
7777
throw new Error(
78-
`[path-nice] copy(): cannot overwrite directory ${src} ` +
78+
`[path-nice] .copy(): cannot overwrite directory ${src} ` +
7979
`with non-directory ${dest}`,
8080
);
8181
}
8282
if (!srcStat.isDirectory() && destStat.isDirectory()) {
8383
throw new Error(
84-
`[path-nice] copy(): cannot overwrite non-directory ${src} ` +
84+
`[path-nice] .copy(): cannot overwrite non-directory ${src} ` +
8585
`with directory ${dest}`,
8686
);
8787
}
8888
}
8989

9090
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
9191
throw new Error(
92-
`[path-nice] copy(): cannot copy ${src} to a subdirectory of self ${dest}`,
92+
`[path-nice] .copy(): cannot copy ${src} to a subdirectory of self ${dest}`,
9393
);
9494
}
9595
return { srcStat, destStat };
@@ -164,7 +164,7 @@ export async function copy(
164164
}
165165
if (areIdentical(srcStat, destStat)) {
166166
throw new Error(
167-
`[path-nice] copy(): cannot copy ${src} to a subdirectory of self ${dest}`,
167+
`[path-nice] .copy(): cannot copy ${src} to a subdirectory of self ${dest}`,
168168
);
169169
}
170170
return checkParentPaths(src, srcStat, destParent);
@@ -212,7 +212,7 @@ export async function copy(
212212
if (srcStat.isDirectory() && options.recursive) {
213213
return onDir(srcStat, destStat, src, dest, options);
214214
} else if (srcStat.isDirectory()) {
215-
throw new Error(`[path-nice] copy(): ${src} is a directory (not copied)`);
215+
throw new Error(`[path-nice] .copy(): ${src} is a directory (not copied)`);
216216
} else if (
217217
srcStat.isFile() ||
218218
srcStat.isCharacterDevice() ||
@@ -222,11 +222,11 @@ export async function copy(
222222
} else if (srcStat.isSymbolicLink()) {
223223
return onLink(destStat, src, dest, options);
224224
} else if (srcStat.isSocket()) {
225-
throw new Error(`[path-nice] copy(): cannot copy a socket file: ${dest}`);
225+
throw new Error(`[path-nice] .copy(): cannot copy a socket file: ${dest}`);
226226
} else if (srcStat.isFIFO()) {
227-
throw new Error(`[path-nice] copy(): cannot copy a FIFO pipe: ${dest}`);
227+
throw new Error(`[path-nice] .copy(): cannot copy a FIFO pipe: ${dest}`);
228228
}
229-
throw new Error(`[path-nice] copy(): cannot copy an unknown file type: ${dest}`);
229+
throw new Error(`[path-nice] .copy(): cannot copy an unknown file type: ${dest}`);
230230
}
231231

232232
function onFile(srcStat: any, destStat: any, src: any, dest: any, options: any) {
@@ -239,7 +239,7 @@ export async function copy(
239239
await unlink(dest);
240240
return _copyFile(srcStat, src, dest, options);
241241
} else if (options.errorOnExist) {
242-
throw new Error(`[path-nice] copy(): ${dest} already exists`);
242+
throw new Error(`[path-nice] .copy(): ${dest} already exists`);
243243
}
244244
}
245245

@@ -334,7 +334,7 @@ export async function copy(
334334
}
335335
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
336336
throw new Error(
337-
`[path-nice] copy(): cannot copy ${resolvedSrc} to a subdirectory of self ` +
337+
`[path-nice] .copy(): cannot copy ${resolvedSrc} to a subdirectory of self ` +
338338
`${resolvedDest}`,
339339
);
340340
}
@@ -344,7 +344,7 @@ export async function copy(
344344
const srcStat = await stat(src);
345345
if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
346346
throw new Error(
347-
`[path-nice] copy(): cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
347+
`[path-nice] .copy(): cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
348348
);
349349
}
350350
return copyLink(resolvedSrc, dest);
@@ -399,26 +399,26 @@ export function copySync(
399399
if (destStat) {
400400
if (areIdentical(srcStat, destStat)) {
401401
throw new Error(
402-
`[path-nice] copySync(): src and dest cannot be the same`,
402+
`[path-nice] .copySync(): src and dest cannot be the same`,
403403
);
404404
}
405405
if (srcStat.isDirectory() && !destStat.isDirectory()) {
406406
throw new Error(
407-
`[path-nice] copySync(): cannot overwrite directory ${src} ` +
407+
`[path-nice] .copySync(): cannot overwrite directory ${src} ` +
408408
`with non-directory ${dest}`,
409409
);
410410
}
411411
if (!srcStat.isDirectory() && destStat.isDirectory()) {
412412
throw new Error(
413-
`[path-nice] copySync(): cannot overwrite non-directory ${src} ` +
413+
`[path-nice] .copySync(): cannot overwrite non-directory ${src} ` +
414414
`with directory ${dest}`,
415415
);
416416
}
417417
}
418418

419419
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
420420
throw new Error(
421-
`[path-nice] copySync(): cannot copy ${src} to a subdirectory of self ${dest}`,
421+
`[path-nice] .copySync(): cannot copy ${src} to a subdirectory of self ${dest}`,
422422
);
423423
}
424424
return { srcStat, destStat };
@@ -495,7 +495,7 @@ export function copySync(
495495
}
496496
if (areIdentical(srcStat, destStat)) {
497497
throw new Error(
498-
`[path-nice] copySync(): cannot copy ${src} to a subdirectory of self ${dest}`,
498+
`[path-nice] .copySync(): cannot copy ${src} to a subdirectory of self ${dest}`,
499499
);
500500
}
501501
return checkParentPaths(src, srcStat, destParent);
@@ -543,7 +543,7 @@ export function copySync(
543543
if (srcStat.isDirectory() && options.recursive) {
544544
return onDir(srcStat, destStat, src, dest, options);
545545
} else if (srcStat.isDirectory()) {
546-
throw new Error(`[path-nice] copySync(): ${src} is a directory (not copied)`);
546+
throw new Error(`[path-nice] .copySync(): ${src} is a directory (not copied)`);
547547
} else if (
548548
srcStat.isFile() ||
549549
srcStat.isCharacterDevice() ||
@@ -553,12 +553,12 @@ export function copySync(
553553
} else if (srcStat.isSymbolicLink()) {
554554
return onLink(destStat, src, dest, options);
555555
} else if (srcStat.isSocket()) {
556-
throw new Error(`[path-nice] copySync(): cannot copy a socket file: ${dest}`);
556+
throw new Error(`[path-nice] .copySync(): cannot copy a socket file: ${dest}`);
557557
} else if (srcStat.isFIFO()) {
558-
throw new Error(`[path-nice] copySync(): cannot copy a FIFO pipe: ${dest}`);
558+
throw new Error(`[path-nice] .copySync(): cannot copy a FIFO pipe: ${dest}`);
559559
}
560560
throw new Error(
561-
`[path-nice] copySync(): cannot copy an unknown file type: ${dest}`,
561+
`[path-nice] .copySync(): cannot copy an unknown file type: ${dest}`,
562562
);
563563
}
564564

@@ -572,7 +572,7 @@ export function copySync(
572572
unlinkSync(dest);
573573
return _copyFile(srcStat, src, dest, options);
574574
} else if (options.errorOnExist) {
575-
throw new Error(`[path-nice] copySync(): ${dest} already exists`);
575+
throw new Error(`[path-nice] .copySync(): ${dest} already exists`);
576576
}
577577
}
578578

@@ -667,7 +667,7 @@ export function copySync(
667667
}
668668
if (isSrcSubdir(resolvedSrc, resolvedDest)) {
669669
throw new Error(
670-
`[path-nice] copySync(): cannot copy ${resolvedSrc} to a subdirectory ` +
670+
`[path-nice] .copySync(): cannot copy ${resolvedSrc} to a subdirectory ` +
671671
`of self ${resolvedDest}`,
672672
);
673673
}
@@ -677,7 +677,7 @@ export function copySync(
677677
const srcStat = statSync(src);
678678
if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) {
679679
throw new Error(
680-
`[path-nice] copySync(): cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
680+
`[path-nice] .copySync(): cannot overwrite ${resolvedDest} with ${resolvedSrc}`,
681681
);
682682
}
683683
return copyLink(resolvedSrc, dest);

src/core/fs/ensure.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ export async function ensureFile(
5757
});
5858
} else {
5959
throw new Error(
60-
`[path-nice] ensureFile(): ${dirname} already exists and is not a directory.`,
60+
`[path-nice] .ensureFile(): ${dirname} already exists and is not a directory.`,
6161
);
6262
}
6363
}
6464

6565
if (stats.isFile()) return;
6666
throw new Error(
67-
'[path-nice] ensureFile(): the path already exists and is not a file.',
67+
'[path-nice] .ensureFile(): the path already exists and is not a file.',
6868
);
6969
}
7070

@@ -97,14 +97,14 @@ export function ensureFileSync(
9797
fs.writeFileSync(target, '', { encoding: 'utf-8', mode: options?.fileMode });
9898
} else {
9999
throw new Error(
100-
`[path-nice] ensureFileSync(): ${dirname} already exists and is not ` +
100+
`[path-nice] .ensureFileSync(): ${dirname} already exists and is not ` +
101101
`a directory.`,
102102
);
103103
}
104104
}
105105

106106
if (stats.isFile()) return;
107107
throw new Error(
108-
'[path-nice] ensureFileSync(): the path already exists and is not a file.',
108+
'[path-nice] .ensureFileSync(): the path already exists and is not a file.',
109109
);
110110
}

src/core/fs/move.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export async function move(
6868
return remove(fs, dest).then(() => _rename(src, dest, overwrite));
6969
}
7070
return pathExists(dest).then((destExists) => {
71-
if (destExists) throw new Error('dest already exists.');
71+
if (destExists) throw new Error('[path-nice] .move(): dest already exists.');
7272
return _rename(src, dest, overwrite);
7373
});
7474
}
@@ -111,23 +111,23 @@ export async function move(
111111
) {
112112
return { srcStat, destStat, isChangingCase: true };
113113
}
114-
throw new Error('[path-nice] move(): src and dest must not be the same.');
114+
throw new Error('[path-nice] .move(): src and dest must not be the same.');
115115
}
116116
if (srcStat.isDirectory() && !destStat.isDirectory()) {
117117
throw new Error(
118-
`[path-nice] move(): cannot overwrite non-directory ${dest} with directory ${src}.`,
118+
`[path-nice] .move(): cannot overwrite non-directory ${dest} with directory ${src}.`,
119119
);
120120
}
121121
if (!srcStat.isDirectory() && destStat.isDirectory()) {
122122
throw new Error(
123-
`[path-nice] move(): cannot overwrite directory '${dest}' with non-directory '${src}'.`,
123+
`[path-nice] .move(): cannot overwrite directory '${dest}' with non-directory '${src}'.`,
124124
);
125125
}
126126
}
127127

128128
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
129129
throw new Error(
130-
`[path-nice] move(): cannot move ${src} to a subdirectory of self ${dest}`,
130+
`[path-nice] .move(): cannot move ${src} to a subdirectory of self ${dest}`,
131131
);
132132
}
133133
return { srcStat, destStat };
@@ -193,7 +193,7 @@ export async function move(
193193
}
194194
if (areIdentical(srcStat, destStat)) {
195195
throw new Error(
196-
`[path-nice] move(): cannot copy ${src} to a subdirectory of self ${dest}`,
196+
`[path-nice] .move(): cannot copy ${src} to a subdirectory of self ${dest}`,
197197
);
198198
}
199199
return checkParentPaths(src, srcStat, destParent);
@@ -239,7 +239,7 @@ export function moveSync(
239239
return _rename(src, dest, overwrite);
240240
}
241241
const destExists = pathExists(dest);
242-
if (destExists) throw new Error('dest already exists.');
242+
if (destExists) throw new Error('[path-nice] .moveSync(): dest already exists.');
243243
return _rename(src, dest, overwrite);
244244
}
245245

@@ -285,26 +285,26 @@ export function moveSync(
285285
return { srcStat, destStat, isChangingCase: true };
286286
}
287287
throw new Error(
288-
'[path-nice] moveSync(): src and dest must not be the same.',
288+
'[path-nice] .moveSync(): src and dest must not be the same.',
289289
);
290290
}
291291
if (srcStat.isDirectory() && !destStat.isDirectory()) {
292292
throw new Error(
293-
`[path-nice] moveSync(): cannot overwrite non-directory ${dest} ` +
293+
`[path-nice] .moveSync(): cannot overwrite non-directory ${dest} ` +
294294
`with directory ${src}.`,
295295
);
296296
}
297297
if (!srcStat.isDirectory() && destStat.isDirectory()) {
298298
throw new Error(
299-
`[path-nice] moveSync(): cannot overwrite directory '${dest}' with ` +
299+
`[path-nice] .moveSync(): cannot overwrite directory '${dest}' with ` +
300300
`non-directory '${src}'.`,
301301
);
302302
}
303303
}
304304

305305
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
306306
throw new Error(
307-
`[path-nice] moveSync(): cannot move ${src} to a subdirectory of self ${dest}`,
307+
`[path-nice] .moveSync(): cannot move ${src} to a subdirectory of self ${dest}`,
308308
);
309309
}
310310
return { srcStat, destStat };
@@ -368,7 +368,7 @@ export function moveSync(
368368
}
369369
if (areIdentical(srcStat, destStat)) {
370370
throw new Error(
371-
`[path-nice] moveSync(): cannot copy ${src} to a subdirectory of ` +
371+
`[path-nice] .moveSync(): cannot copy ${src} to a subdirectory of ` +
372372
`self ${dest}`,
373373
);
374374
}

0 commit comments

Comments
 (0)