Skip to content

Commit 3e4c1aa

Browse files
committed
Small improvements in error handler
1 parent 09f3d04 commit 3e4c1aa

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

tools/office-cmdlet-updater/controllers/cli.controller.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
class CliController {
2-
constructor(cliService, cmdletService, markdownController) {
3-
this.cliServoce = cliService;
2+
constructor(
3+
cliService,
4+
cmdletService,
5+
markdownController,
6+
powerShellService
7+
) {
8+
this.cliService = cliService;
49
this.cmdletService = cmdletService;
510
this.markdownController = markdownController;
11+
this.powerShellService = powerShellService;
12+
}
13+
start(argv) {
14+
try {
15+
this.startCli(argv);
16+
} catch (e) {
17+
this.powerShellService.dispose();
18+
console.error(e.message);
19+
}
620
}
721

822
startCli(argv) {
9-
this.cliServoce.addOption({
23+
this.cliService.addOption({
1024
option: '-m --module <module>',
1125
description: 'update documentation for module',
1226
defaultValue: 'all',
@@ -21,27 +35,25 @@ class CliController {
2135
}
2236
});
2337

24-
this.cliServoce.addOption({
38+
this.cliService.addOption({
2539
option: '-c --cmdlet <cmdet>',
2640
description: 'update documentation for cmdlet in module',
2741
action: (cli) => {
2842
const { module, cmdlet } = cli;
2943

3044
if (module === 'all' && cmdlet) {
31-
throw new Error('You must specify a module for cmdet.');
45+
throw new Error('You must specify a module for cmdlet.');
3246
}
3347
}
3448
});
3549

36-
this.cliServoce.start(argv, async (cli) => {
50+
this.cliService.start(argv, async (cli) => {
3751
const { module, cmdlet } = cli;
3852

39-
this.markdownController.updateMarkdown({
53+
await this.markdownController.updateMarkdown({
4054
moduleName: module,
4155
cmdlet
4256
});
43-
console.log(module);
44-
console.log(cmdlet);
4557
});
4658
}
4759
}

tools/office-cmdlet-updater/controllers/markdown.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MarkdownController {
2323

2424
if (err) {
2525
this.powerShellService.dispose();
26-
throw new Error(err);
26+
console.error(err.message);
2727
}
2828
}
2929
);

tools/office-cmdlet-updater/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
const container = require('./helpers/di.container')();
22

3-
try {
4-
const cliController = container.resolve('cliController');
3+
const cliController = container.resolve('cliController');
54

6-
cliController.startCli(process.argv);
7-
} catch (e) {
8-
console.log(e);
9-
}
5+
cliController.start(process.argv);

tools/office-cmdlet-updater/services/markdown.service.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class MarkdownService {
4040
(file) => this._filterCmdlets(file, cmdlet)
4141
);
4242

43+
if (!mdFiles.length) {
44+
throw new Error(
45+
`Can't find cmdlet "${cmdlet}" in module "${doc.name}"`
46+
);
47+
}
48+
4349
mdFiles.forEach((file) => {
4450
this.queue
4551
.push({ file, doc })

0 commit comments

Comments
 (0)