Skip to content

Commit d9226f8

Browse files
authored
[api-extractor] Fix error handling when encountering changed APIs (#5226)
* Fix error handling when encountering changed APIs * Rush change
1 parent 8c31995 commit d9226f8

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

apps/api-extractor/src/cli/ApiExtractorCommandLine.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import * as os from 'os';
55

66
import { CommandLineParser, type CommandLineFlagParameter } from '@rushstack/ts-command-line';
7-
import { InternalError } from '@rushstack/node-core-library';
7+
import { AlreadyReportedError, InternalError } from '@rushstack/node-core-library';
88
import { Colorize } from '@rushstack/terminal';
99

1010
import { RunAction } from './RunAction';
@@ -42,10 +42,12 @@ export class ApiExtractorCommandLine extends CommandLineParser {
4242
await super.onExecuteAsync();
4343
process.exitCode = 0;
4444
} catch (error) {
45-
if (this._debugParameter.value) {
46-
console.error(os.EOL + error.stack);
47-
} else {
48-
console.error(os.EOL + Colorize.red('ERROR: ' + error.message.trim()));
45+
if (!(error instanceof AlreadyReportedError)) {
46+
if (this._debugParameter.value) {
47+
console.error(os.EOL + error.stack);
48+
} else {
49+
console.error(os.EOL + Colorize.red('ERROR: ' + error.message.trim()));
50+
}
4951
}
5052
}
5153
}

apps/api-extractor/src/cli/RunAction.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33

44
import * as os from 'os';
55
import * as path from 'path';
6-
import { PackageJsonLookup, FileSystem, type IPackageJson, Path } from '@rushstack/node-core-library';
6+
import {
7+
PackageJsonLookup,
8+
FileSystem,
9+
type IPackageJson,
10+
Path,
11+
AlreadyReportedError
12+
} from '@rushstack/node-core-library';
713
import { Colorize } from '@rushstack/terminal';
814
import {
915
CommandLineAction,
@@ -138,13 +144,12 @@ export class RunAction extends CommandLineAction {
138144
if (extractorResult.succeeded) {
139145
console.log(os.EOL + 'API Extractor completed successfully');
140146
} else {
141-
process.exitCode = 1;
142-
143147
if (extractorResult.errorCount > 0) {
144148
console.log(os.EOL + Colorize.red('API Extractor completed with errors'));
145149
} else {
146150
console.log(os.EOL + Colorize.yellow('API Extractor completed with warnings'));
147151
}
152+
throw new AlreadyReportedError();
148153
}
149154
}
150155
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fixes API extractor error handling when changed APIs are encountered and the \"--local\" flag is not specified",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor"
10+
}

0 commit comments

Comments
 (0)