UNPKG

1.11 kBJavaScriptView Raw
1const CustomError = require('custom-error-class')
2
3class FileNotFound extends CustomError {
4 constructor (fileName) {
5 super(`No such file or directory: '${fileName}'.`)
6 this.code = 'ENOENT'
7 this.errno = 2
8 }
9}
10
11class DirectoryNotEmpty extends CustomError {
12 constructor (dirName) {
13 super(`Directory '${dirName}' is not empty.`)
14 this.code = 'ENOTEMPTY'
15 this.errno = 39
16 }
17}
18
19class PathAlreadyExists extends CustomError {
20 constructor (dirName) {
21 super(`Path ${dirName} already exists.`)
22 this.code = 'EEXIST'
23 this.errno = 17
24 }
25}
26
27class BadFileDescriptor extends CustomError {
28 constructor (msg) {
29 super(msg)
30 this.code = 'EBADF'
31 this.errno = 9
32 }
33}
34
35class InvalidArgument extends CustomError {
36 constructor (msg) {
37 super(msg)
38 this.code = 'EINVAL'
39 this.errno = 22
40 }
41}
42
43class InvalidPermission extends CustomError {
44 constructor (msg) {
45 super(msg)
46 this.code = 'EPERM'
47 this.errno = 1
48 }
49}
50
51module.exports = {
52 FileNotFound,
53 DirectoryNotEmpty,
54 PathAlreadyExists,
55 BadFileDescriptor,
56 InvalidArgument,
57 InvalidPermission
58}