Skip to content

Commit c91e07f

Browse files
committed
updated typescript
1 parent de68f83 commit c91e07f

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "directory-validator",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "CLI Tool to validate directory structures.",
55
"main": "lib/index.js",
66
"bin": {
@@ -20,7 +20,7 @@
2020
"@types/node": "^14.14.37",
2121
"jest": "^26.6.3",
2222
"ts-jest": "^26.5.4",
23-
"typescript": "^4.2.3"
23+
"typescript": "^4.5.5"
2424
},
2525
"dependencies": {
2626
"ajv": "^8.0.2",

src/errors.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ export class JsonParseError extends Error {
44
err: Error;
55
filePath: string;
66

7-
constructor(err: Error, filePath: string) {
8-
super(err.message);
9-
this.err = err;
7+
constructor(err: unknown, filePath: string) {
8+
const parsedError = isError(err) ? err : new Error('unknown error');
9+
10+
super(parsedError.message);
11+
this.err = parsedError;
1012
this.filePath = filePath;
1113
}
1214
}
@@ -46,3 +48,7 @@ export class ValidatorInvalidPathError extends Error {
4648
this.path = path;
4749
}
4850
}
51+
52+
export function isError(err: any): err is Error {
53+
return Boolean(err && err.stack && err.message);
54+
}

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ if (selectedOptions.init) {
7878
ignoreFilesGlob: selectedOptions.ignoreFiles,
7979
});
8080

81+
console.log('Directory successfully validated!');
82+
8183
if (selectedOptions.print && results.asciiTree) {
8284
console.log(
8385
results.asciiTree
@@ -114,12 +116,13 @@ if (selectedOptions.init) {
114116
} else if (err instanceof errors.ValidatorInvalidPathError) {
115117
console.error(errorTitle);
116118
console.error('\t', dash, err.path.red, 'was not validated');
117-
} else {
119+
} else if (errors.isError(err)) {
118120
console.error(errorTitle);
119121
console.error('\t', dash, err.message.red);
122+
} else {
123+
console.error('Unknown error');
120124
}
121125

122-
console.error();
123126
process.exit(1);
124127
}
125128
}

src/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function getConfig(rulesPath: string): types.Config {
1717

1818
try {
1919
configJson = JSON.parse(fs.readFileSync(rulesPath, 'utf8'));
20-
} catch (err: any) {
20+
} catch (err) {
2121
throw new errors.JsonParseError(err, rulesPath);
2222
}
2323

0 commit comments

Comments
 (0)