Skip to content

Commit 50a8f5a

Browse files
committed
fix: improve error handling
1 parent 04514af commit 50a8f5a

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/docs.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ import { TopicDitamap } from './ditamap/topic-ditamap';
2727
import { events, punctuate } from './utils';
2828
import { HelpReference } from './ditamap/help-reference';
2929

30+
function emitNoTopicMetadataWarning(topic: string): void {
31+
events.emit(
32+
'warning',
33+
`No metadata for topic ${chalk.bold(
34+
topic
35+
)}. That topic owner must add topic metadata in the oclif section in the package.json file within their plugin.`
36+
);
37+
}
38+
3039
export class Docs {
3140
public constructor(
3241
private outputDir: string,
@@ -50,22 +59,21 @@ export class Docs {
5059
);
5160
let description = asString(topicMeta.description);
5261
if (!description && !topicMeta.external) {
53-
// Punctuate the description in place of longDescription
5462
description = punctuate(asString(topicMeta.description));
5563
if (!description) {
5664
events.emit(
5765
'warning',
5866
`No description for topic ${chalk.bold(
5967
topic
60-
)}. Skipping until topic owner adds topic metadata, that includes longDescription, in the oclif section in the package.json file within their plugin.`
68+
)}. Skipping until topic owner adds topic metadata in the oclif section in the package.json file within their plugin.`
6169
);
6270
return;
6371
}
6472
}
6573

6674
const subTopicNames = [];
6775
const commandIds = [];
68-
// const commandFileNames = [];
76+
6977
for (const subtopic of Object.keys(subtopics)) {
7078
const subtopicOrCommand = subtopics[subtopic];
7179
try {
@@ -81,13 +89,7 @@ export class Docs {
8189
const subTopicsMeta = ensureJsonMap(topicMeta.subtopics);
8290

8391
if (!subTopicsMeta[subtopic]) {
84-
const fullTopicPath = `${topic}:${subtopic}`;
85-
events.emit(
86-
'warning',
87-
`No metadata for topic ${chalk.bold(
88-
fullTopicPath
89-
)}. That topic owner must add topic metadata in the oclif section in the package.json file within their plugin.`
90-
);
92+
emitNoTopicMetadataWarning(`${topic}:${subtopic}`);
9193
continue;
9294
}
9395

@@ -108,7 +110,11 @@ export class Docs {
108110
commandIds.push(command.id);
109111
}
110112
} catch (error) {
111-
events.emit('warning', `Can't create topic for ${topic}:${subtopic}: ${error.message}\n`);
113+
if (error.name === 'UnexpectedValueTypeError') {
114+
emitNoTopicMetadataWarning(`${topic}:${subtopic}`);
115+
} else {
116+
events.emit('warning', `Can't create topic for ${topic}:${subtopic}: ${error.message}\n`);
117+
}
112118
}
113119
}
114120

0 commit comments

Comments
 (0)