From 7ef3648530c961ba20f623a07596b75e479e074a Mon Sep 17 00:00:00 2001 From: Daniel Nadeau <3473356+D4N14L@users.noreply.github.com> Date: Mon, 12 May 2025 17:34:38 -0700 Subject: [PATCH 1/2] Fix error handling when encountering changed APIs --- .../api-extractor/src/cli/ApiExtractorCommandLine.ts | 12 +++++++----- apps/api-extractor/src/cli/RunAction.ts | 11 ++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts b/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts index a2dc21f1103..56c05a5cc6b 100644 --- a/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts +++ b/apps/api-extractor/src/cli/ApiExtractorCommandLine.ts @@ -4,7 +4,7 @@ import * as os from 'os'; import { CommandLineParser, type CommandLineFlagParameter } from '@rushstack/ts-command-line'; -import { InternalError } from '@rushstack/node-core-library'; +import { AlreadyReportedError, InternalError } from '@rushstack/node-core-library'; import { Colorize } from '@rushstack/terminal'; import { RunAction } from './RunAction'; @@ -42,10 +42,12 @@ export class ApiExtractorCommandLine extends CommandLineParser { await super.onExecuteAsync(); process.exitCode = 0; } catch (error) { - if (this._debugParameter.value) { - console.error(os.EOL + error.stack); - } else { - console.error(os.EOL + Colorize.red('ERROR: ' + error.message.trim())); + if (!(error instanceof AlreadyReportedError)) { + if (this._debugParameter.value) { + console.error(os.EOL + error.stack); + } else { + console.error(os.EOL + Colorize.red('ERROR: ' + error.message.trim())); + } } } } diff --git a/apps/api-extractor/src/cli/RunAction.ts b/apps/api-extractor/src/cli/RunAction.ts index ebfcfeae3e7..4bfbf48333c 100644 --- a/apps/api-extractor/src/cli/RunAction.ts +++ b/apps/api-extractor/src/cli/RunAction.ts @@ -3,7 +3,13 @@ import * as os from 'os'; import * as path from 'path'; -import { PackageJsonLookup, FileSystem, type IPackageJson, Path } from '@rushstack/node-core-library'; +import { + PackageJsonLookup, + FileSystem, + type IPackageJson, + Path, + AlreadyReportedError +} from '@rushstack/node-core-library'; import { Colorize } from '@rushstack/terminal'; import { CommandLineAction, @@ -138,13 +144,12 @@ export class RunAction extends CommandLineAction { if (extractorResult.succeeded) { console.log(os.EOL + 'API Extractor completed successfully'); } else { - process.exitCode = 1; - if (extractorResult.errorCount > 0) { console.log(os.EOL + Colorize.red('API Extractor completed with errors')); } else { console.log(os.EOL + Colorize.yellow('API Extractor completed with warnings')); } + throw new AlreadyReportedError(); } } } From ed4db65e0cc4d730376ae21ea1fdd8edd3764c29 Mon Sep 17 00:00:00 2001 From: Daniel Nadeau <3473356+D4N14L@users.noreply.github.com> Date: Mon, 12 May 2025 17:41:42 -0700 Subject: [PATCH 2/2] Rush change --- .../user-danade-FixTsCommandLine_2025-05-13-00-41.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/api-extractor/user-danade-FixTsCommandLine_2025-05-13-00-41.json diff --git a/common/changes/@microsoft/api-extractor/user-danade-FixTsCommandLine_2025-05-13-00-41.json b/common/changes/@microsoft/api-extractor/user-danade-FixTsCommandLine_2025-05-13-00-41.json new file mode 100644 index 00000000000..51c0b342664 --- /dev/null +++ b/common/changes/@microsoft/api-extractor/user-danade-FixTsCommandLine_2025-05-13-00-41.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/api-extractor", + "comment": "Fixes API extractor error handling when changed APIs are encountered and the \"--local\" flag is not specified", + "type": "patch" + } + ], + "packageName": "@microsoft/api-extractor" +} \ No newline at end of file