Skip to content

Commit 930b3cc

Browse files
authored
Merge pull request microsoft#239 from Microsoft/pgonzal/ae-error-strings
Audit API Extractor error strings
2 parents 1241bf4 + a6207b5 commit 930b3cc

19 files changed

Lines changed: 132 additions & 103 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Improved the wording of many error messages",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor",
10+
"email": "pgonzal@users.noreply.github.com"
11+
}

‎libraries/api-extractor/src/ApiDefinitionReference.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ export default class ApiDefinitionReference {
131131
apiDefRefParts.memberName = parts[2] ? parts[2] : ''; // e.g. equals
132132
} else {
133133
// the export name is required
134-
throw reportError(`Api reference expression contains invalid characters: ${apiReferenceExpr}`);
134+
throw reportError(`The API item reference contains an invalid "exportName.memberName"`
135+
+ ` expression: "${apiReferenceExpr}"`);
135136
}
136137

137138
if (!apiReferenceExpr.match(ApiDefinitionReference._exportRegEx)) {
138-
throw reportError(`Api reference expression contains invalid characters: ${apiReferenceExpr}`);
139+
throw reportError(`The API item reference contains invalid characters: "${apiReferenceExpr}"`);
139140
}
140141

141142
return ApiDefinitionReference.createFromParts(apiDefRefParts);

‎libraries/api-extractor/src/DocElementParser.ts‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default class DocElementParser {
7272
break;
7373
}
7474

75-
if (token.type === TokenType.Tag) {
75+
if (token.type === TokenType.BlockTag) {
7676
switch (token.tag) {
7777
case '@see':
7878
tokenizer.getToken();
@@ -85,12 +85,13 @@ export default class DocElementParser {
8585
parsing = false; // end of summary tokens
8686
break;
8787
}
88-
} else if (token.type === TokenType.Inline) {
88+
} else if (token.type === TokenType.InlineTag) {
8989
switch (token.tag) {
9090
case '@inheritdoc':
9191
tokenizer.getToken();
9292
if (docElements.length > 0 || documentation.summary.length > 0) {
93-
documentation.reportError('Cannot provide summary in AEDoc if @inheritdoc tag is given');
93+
documentation.reportError('A summary block is not allowed here,'
94+
+ ' because the @inheritdoc target provides the summary');
9495
}
9596
documentation.incompleteInheritdocs.push(token);
9697
documentation.isDocInherited = true;
@@ -114,7 +115,7 @@ export default class DocElementParser {
114115
docElements.push({kind: 'textDocElement', value: token.text} as ITextElement);
115116
tokenizer.getToken();
116117
} else {
117-
documentation.reportError(`Unidentifiable Token ${token.type} ${token.tag} ${token.text}`);
118+
documentation.reportError(`Unidentifiable Token ${token.type} ${token.tag} "${token.text}"`);
118119
}
119120
}
120121
return docElements;
@@ -125,7 +126,7 @@ export default class DocElementParser {
125126
* linkDocElement with the corresponding information. If the corresponding inline tag \@link is
126127
* not formatted correctly an error will be reported.
127128
*
128-
* The format for the \@link tag is {\@link url or API defintion reference | display text}, where
129+
* The format for the \@link tag is {\@link URL or API defintion reference | display text}, where
129130
* the '|' is only needed if the optional display text is given.
130131
*
131132
* Examples:
@@ -136,7 +137,7 @@ export default class DocElementParser {
136137
*/
137138
public static parseLinkTag(documentation: ApiDocumentation, tokenItem: Token): IHrefLinkElement | ICodeLinkElement {
138139
if (!tokenItem.text) {
139-
documentation.reportError('Invalid @link inline token, a url or API definition reference must be given');
140+
documentation.reportError('The {@link} tag must include a URL or API item reference');
140141
return;
141142
}
142143

@@ -148,7 +149,7 @@ export default class DocElementParser {
148149
}
149150
});
150151
if (pipeSplitContent.length > 2) {
151-
documentation.reportError('Invalid @link parameters, at most one pipe character allowed.');
152+
documentation.reportError('The {@link} tag contains more than one pipe character ("|")');
152153
return;
153154
}
154155

@@ -157,9 +158,10 @@ export default class DocElementParser {
157158
if (tokenItem.text.match(this._hrefRegEx)) {
158159
const urlContent: string[] = pipeSplitContent[0].split(' ');
159160

160-
// Make sure only a single url is given
161+
// Make sure only a single URL is given
161162
if (urlContent.length > 1 && urlContent[1] !== '' ) {
162-
documentation.reportError('Invalid @link parameter, url must be a single string.');
163+
documentation.reportError('The {@link} tag contains additional spaces after the URL;'
164+
+ ' if the URL contains spaces, encode them using %20; for display text, use a pipe delimiter ("|")');
163165
return;
164166
}
165167

@@ -195,7 +197,8 @@ export default class DocElementParser {
195197
if (linkDocElement && pipeSplitContent.length > 1) {
196198
const displayTextParts: string[] = pipeSplitContent[1].match(this._wordRegEx);
197199
if (displayTextParts && displayTextParts[0].length !== pipeSplitContent[1].length) {
198-
documentation.reportError('Display name in @link token may only contain alphabetic characters.');
200+
documentation.reportError(`The {@link} tag\'s display text contains unsupported `
201+
+ ` symbols: "${pipeSplitContent[1]}"`);
199202
return;
200203
}
201204
// Full match is valid text
@@ -218,8 +221,8 @@ export default class DocElementParser {
218221
// Check to make sure the API definition reference is at most one string
219222
const tokenChunks: string[] = token.text.split(' ');
220223
if (tokenChunks.length > 1) {
221-
documentation.reportError('Too many parameters for @inheritdoc inline tag.' +
222-
'The format should be {@inheritdoc scopeName/packageName:exportName}. Extra parameters are ignored');
224+
documentation.reportError('The {@inheritdoc} tag does not match the expected pattern' +
225+
' "{@inheritdoc @scopeName/packageName:exportName}"');
223226
return;
224227
}
225228

@@ -231,7 +234,7 @@ export default class DocElementParser {
231234
);
232235
// if API reference expression is formatted incorrectly then apiDefinitionRef will be undefined
233236
if (!apiDefinitionRef) {
234-
documentation.reportError('Incorrecty formatted API definition reference');
237+
documentation.reportError(`Incorrectly formatted API item reference: "${token.text}"`);
235238
return;
236239
}
237240

‎libraries/api-extractor/src/IDocElement.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export interface IHrefLinkElement extends IBaseDocElement {
3333
referenceType: 'href';
3434

3535
/**
36-
* The url that this link element references.
36+
* The URL that this link element references.
3737
*/
3838
targetUrl: string;
3939

@@ -74,7 +74,7 @@ export interface ICodeLinkElement extends IBaseDocElement {
7474
memberName?: string;
7575

7676
/**
77-
* Optional text to display in place of the API reference string url that is
77+
* Optional text to display in place of the API reference string URL that is
7878
* constructed from the ts-spec tool.
7979
*/
8080
value?: string;

‎libraries/api-extractor/src/Token.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ export enum TokenType {
88
Text,
99

1010
/**
11-
* A Token that specifies a tag.
12-
* Example: \@link, \@internal, etc.
11+
* A Token representing an AEDoc block tag.
12+
* Example: \@public, \@remarks, etc.
1313
*/
14-
Tag,
14+
BlockTag,
1515

1616
/**
17-
* This is a specific kind of Tag that is important to
18-
* distinguish because it contains additional parameters.
17+
* A Token representing an AEDoc inline tag. Inline tags must be enclosed in
18+
* curly braces, which may include parameters.
1919
*
2020
* Example:
2121
* \{@link http://microosft.com | microsoft home \}
2222
* \{@inheritdoc @ microsoft/sp-core-library:Guid.newGuid \}
2323
*/
24-
Inline
24+
InlineTag
2525
}
2626

2727
/**

‎libraries/api-extractor/src/Tokenizer.ts‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default class Tokenizer {
5050
let token: Token;
5151
value = sanitizedTokens[i];
5252
if (value.charAt(0) === '@') {
53-
token = new Token(TokenType.Tag, value);
53+
token = new Token(TokenType.BlockTag, value);
5454
} else if (value.charAt(0) === '{' && value.charAt(value.length - 1) === '}') {
5555
token = this._tokenizeInline(value); // Can return undefined if invalid inline tag
5656
} else {
@@ -71,20 +71,21 @@ export default class Tokenizer {
7171
*/
7272
protected _tokenizeInline(docEntry: string): Token {
7373
if (docEntry.charAt(0) !== '{' || docEntry.charAt(docEntry.length - 1) !== '}') {
74-
this._reportError('All inline tags should be wrapped inside curly braces.');
75-
return;
74+
// This is a program bug, since _tokenizeDocs() checks this condition before calling
75+
this._reportError('The AEDoc tag is not enclosed in "{" and "}"');
7676
}
7777
const tokenContent: string = docEntry.slice(1, docEntry.length - 1).trim();
7878

7979
if (tokenContent.charAt(0) !== '@') {
80-
this._reportError('Content of inline tags should start with a leading \'@\'.');
80+
// This is a program bug, since it should have already been validated by the Tokenizer
81+
this._reportError('The AEDoc tag does not start with "@".');
8182
return;
8283
}
8384

8485
const unescapedCurlyBraces: RegExp = /([^\\])({|}[^$])/gi;
8586
if (unescapedCurlyBraces.test(tokenContent)) {
86-
this._reportError(`Unescaped '{' or '}' detected inside an inline tag. ` +
87-
'Use \\ to escape curly braces inside inline tags.');
87+
this._reportError(`An unescaped "{" or "}" character was found inside an inline tag. ` +
88+
'Use a backslash ("\\") to escape curly braces.');
8889
return;
8990
}
9091

@@ -93,20 +94,21 @@ export default class Tokenizer {
9394
const tokenChunks: string[] = tokenContent.split(/\s+/gi);
9495
if (tokenChunks[0] === '@link') {
9596
if (tokenChunks.length < 2) {
96-
this._reportError('Too few parameters for @link inline tag.');
97+
this._reportError('The {@link} tag must include a URL or API item reference');
9798
return;
9899
}
99100

100101
tokenChunks.shift(); // Gets rid of '@link'
101-
const token: Token = new Token(TokenType.Inline, '@link', tokenChunks.join(' '));
102+
const token: Token = new Token(TokenType.InlineTag, '@link', tokenChunks.join(' '));
102103
return token;
103104
} else if (tokenChunks[0] === '@inheritdoc') {
104105
tokenChunks.shift(); // Gets rid of '@inheritdoc'
105-
const token: Token = new Token(TokenType.Inline, '@inheritdoc', tokenChunks.join(' '));
106+
const token: Token = new Token(TokenType.InlineTag, '@inheritdoc', tokenChunks.join(' '));
106107
return token;
107108
}
108109

109-
this._reportError('Unknown tag name for inline tag.');
110+
// This is a program bug
111+
this._reportError('Invalid call to _tokenizeInline()');
110112
return;
111113
}
112114

0 commit comments

Comments
 (0)