-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patherrorHandling.ts
47 lines (39 loc) · 1.1 KB
/
errorHandling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import coffee, { errors } from "https://deno.land/x/coffee/mod.ts";
// No Config Dir :
try {
coffee.load({ configDir: "./bad-config-dir" });
} catch (e) {
if (e instanceof errors.NoConfigDir) {
// now IDE knows about "e" and can provide hints.
e.message; // "./bad-config-dir" directory is not exists.
}
}
// No Config File :
try {
coffee.load({ configDir: "./bad" });
} catch (e) {
if (e instanceof errors.NoConfigFile) {
/* if coffee didn't see any valid config file with allowed extention,
* it will throw a NoConfigFile error.
*/
e.message; // there is no config file in "./bad" directory.
}
}
// Bad Config Path :
try {
coffee.load({ configDir: "./config" });
coffee.get("database.entry").string();
} catch (e) {
if (e instanceof errors.BadConfigPath) {
e.message; // try to get an undefined path "database.entry".
}
}
// Bad Config Type :
try {
coffee.load({ configDir: "./config" });
coffee.get("database.name").number();
} catch (e) {
if (e instanceof errors.BadConfigType) {
e.message; // "my-db-name" in path : "database.name" is not a number.
}
}