-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api-extractor] UnhandledPromiseRejectionWarning #1765
Comments
Since you were interested in improving the API Extractor diagnostics, here's some notes about how I debugged it. First I created a VS Code debug configuration like this: launch.json {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/scripts/check_core_api_changes.js"
}
]
} The VS Code debugger stopped in AstSymbolTable.ts if (options.isExternal !== astSymbol.isExternal) {
throw new InternalError(`Cannot assign isExternal=${options.isExternal} for`
+ ` the symbol ${astSymbol.localName} because it was previously registered`
+ ` with isExternal=${astSymbol.isExternal}`);
} In the debug console, I looked at astSymbol._astDeclarations[0].declaration.getSourceFile().fileName ...which shows it is talking about astSymbol._astDeclarations[0].declaration.getSourceFile().pos That tells us character position is 2671. To translate it to a line number, I did this: astSymbol._astDeclarations[0].declaration.getSourceFile().getLineAndCharacterOfPosition(2671) ...which points us to this export: @types/react/index.d.ts
That is not the modern good way to import React. Some code is probably mixing together Regardless, API Extractor assigned Before moving on though, let's figure out which file has the bad import, because fixing that may provide a workaround. If we go up the call stack a couple records, the call is coming from this code: ExportAnalyzer.ts } else if (declaration.kind === ts.SyntaxKind.ImportClause) {
// EXAMPLE:
// "import A, { B } from './A';"
//
// ImportDeclaration:
// ImportKeyword: pre=[import] sep=[ ]
// ImportClause: <------------- declaration (referring to A)
// Identifier: pre=[A]
// CommaToken: pre=[,] sep=[ ]
// NamedImports:
// FirstPunctuation: pre=[{] sep=[ ]
// SyntaxList:
// ImportSpecifier:
// Identifier: pre=[B] sep=[ ]
// CloseBraceToken: pre=[}] sep=[ ]
// FromKeyword: pre=[from] sep=[ ]
// StringLiteral: pre=['./A']
// SemicolonToken: pre=[;]
const importClause: ts.ImportClause = declaration as ts.ImportClause;
const exportName: string = importClause.name ?
importClause.name.getText().trim() : ts.InternalSymbolName.Default;
if (externalModulePath !== undefined) {
return this._fetchAstImport(declarationSymbol, {
importKind: AstImportKind.DefaultImport,
modulePath: externalModulePath,
exportName
});
} Printing
rushstack/apps/api-extractor/src/analyzer/AstSymbolTable.ts Lines 511 to 513 in 64ebf51
To avoid breaking on every single symbol, I changed it to be a conditional breakpoint looking for the expression kibana/target/types/plugins/data/public/types.d.ts /// <reference types="react" />
import { CoreStart } from 'src/core/public';
import { IStorageWrapper } from 'src/plugins/kibana_utils/public';
import { UiActionsSetup, UiActionsStart } from 'src/plugins/ui_actions/public';
. . .
Let me investigate that a bit more and follow up. |
Returning to the above example, the analyzer encounters kibana/target/types/plugins/data/public/types.d.ts /// <reference types="react" />
. . .
export interface DataPublicPluginStart {
. . .
ui: {
IndexPatternSelect: React.ComponentType<IndexPatternSelectProps>;
SearchBar: React.ComponentType<StatefulSearchBarProps>;
};
} When it sees the But when The rushstack/apps/api-extractor/src/analyzer/ExportAnalyzer.ts Lines 330 to 366 in 5627415
But debugging reveals that it starts off already inside rushstack/apps/api-extractor/src/analyzer/AstSymbolTable.ts Lines 318 to 323 in 5627415
The Now Normally when the analyzer traverses into an external module, it stops and returns an A simpler solution would be to ignore the I'm thinking of two alternative ways to approach this:
(There is also the problem TypeScript permits a single symbol to have merged declarations coming from multiple source files, but we'll continue to consider that out of scope for now heheh.) |
Oops I actually forgot about the original src/dev/run_check_core_api_changes.ts (async () => {
. . .
const results = await Promise.all(
Object.keys(folderMapping).map(srcFolder =>
run(srcFolder, folderMapping[srcFolder], { log, opts })
)
);
if (results.find(r => r === false) !== undefined) {
process.exitCode = 1;
}
})(); // <=== MISSING .catch() HANDLER HERE @lizozom You guys should definitely fix that and enable the |
Here's a sketch of an implementation for idea #1 above: PR #1767 |
@octogonz thank you so much for the detailed response. |
Fixed by PR #1767 which was published with API Extractor 7.7.12. |
BTW I've also improved |
Please prefix the issue title with the project name i.e. [rush], [api-extractor] etc.
Is this a feature or a bug?
Please describe the actual behavior.
Trying to build docs for Kibana, results in the following error:
If the issue is a bug, how can we reproduce it? Please provide detailed steps and include a GitHub branch if applicable. Your issue will get resolved faster if you can make it easy to investigate.
Checkout this KIbana branch https://github.com/lizozom/kibana/tree/newplatform/docs-test
Run
yarn kbn bootstrap
to install dependenciesRun
node scripts/check_core_api_changes.js
to start generating the docs.After ~1min you'll see the error mentioned.
What is the expected behavior?
Docs should be generated
If this is a bug, please provide the tool version, Node.js version, and OS.
The text was updated successfully, but these errors were encountered: