@fern-api/fern-api-dev 4.68.4 → 4.68.5-1-g8e557fa8d81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cli.cjs +577 -208
  2. package/package.json +1 -1
package/cli.cjs CHANGED
@@ -627016,7 +627016,7 @@ var AccessTokenPosthogManager = class {
627016
627016
  properties: {
627017
627017
  ...event,
627018
627018
  ...event.properties,
627019
- version: "4.68.4",
627019
+ version: "4.68.5-1-g8e557fa8d81",
627020
627020
  usingAccessToken: true
627021
627021
  }
627022
627022
  });
@@ -627070,7 +627070,7 @@ var UserPosthogManager = class {
627070
627070
  distinctId: this.userId ?? await this.getPersistedDistinctId(),
627071
627071
  event: "CLI",
627072
627072
  properties: {
627073
- version: "4.68.4",
627073
+ version: "4.68.5-1-g8e557fa8d81",
627074
627074
  ...event,
627075
627075
  ...event.properties,
627076
627076
  usingAccessToken: false,
@@ -844122,7 +844122,7 @@ var LOCAL_STORAGE_FOLDER4 = ".fern-dev";
844122
844122
  var LOGS_FOLDER_NAME = "logs";
844123
844123
  var MAX_LOGS_DIR_SIZE_BYTES = 100 * 1024 * 1024;
844124
844124
  function getCliSource() {
844125
- const version7 = "4.68.4";
844125
+ const version7 = "4.68.5-1-g8e557fa8d81";
844126
844126
  return `cli@${version7}`;
844127
844127
  }
844128
844128
  var DebugLogger = class {
@@ -855372,7 +855372,7 @@ var LegacyDocsPublisher = class {
855372
855372
  previewId,
855373
855373
  disableTemplates: void 0,
855374
855374
  skipUpload,
855375
- cliVersion: "4.68.4"
855375
+ cliVersion: "4.68.5-1-g8e557fa8d81"
855376
855376
  });
855377
855377
  if (taskContext.getResult() === TaskResult.Failure) {
855378
855378
  return { success: false };
@@ -928615,7 +928615,10 @@ var SentryClient = class {
928615
928615
  if (isTelemetryEnabled && sentryDsn != null && sentryDsn.length > 0) {
928616
928616
  const sentryEnvironment = "development";
928617
928617
  if (sentryEnvironment == null || sentryEnvironment.length === 0) {
928618
- throw new Error("SENTRY_ENVIRONMENT must be set when SENTRY_DSN is configured");
928618
+ throw new CliError({
928619
+ message: "SENTRY_ENVIRONMENT must be set when SENTRY_DSN is configured",
928620
+ code: CliError.Code.ConfigError
928621
+ });
928619
928622
  }
928620
928623
  this.sentry = init2({
928621
928624
  dsn: sentryDsn,
@@ -928654,7 +928657,10 @@ var StdoutRedirector = class {
928654
928657
  redirected = false;
928655
928658
  redirect() {
928656
928659
  if (this.redirected) {
928657
- throw new Error("StdoutRedirector: already redirected \u2014 did you forget to restore()?");
928660
+ throw new CliError({
928661
+ message: "StdoutRedirector: already redirected \u2014 did you forget to restore()?",
928662
+ code: CliError.Code.InternalError
928663
+ });
928658
928664
  }
928659
928665
  this.originalWrite = process.stdout.write;
928660
928666
  process.stdout.write = process.stderr.write.bind(process.stderr);
@@ -928963,7 +928969,7 @@ async function normalizeGeneratorName2(generatorImage) {
928963
928969
  });
928964
928970
  const generatorResponse = await client3.generators.getGeneratorByImage({ dockerImage: generatorImage });
928965
928971
  if (!generatorResponse.ok || generatorResponse.body == null) {
928966
- throw new Error(`Generator ${generatorImage} not found`);
928972
+ throw new CliError({ message: `Generator ${generatorImage} not found`, code: CliError.Code.InternalError });
928967
928973
  }
928968
928974
  return generatorResponse.body.displayName;
928969
928975
  }
@@ -929144,9 +929150,16 @@ async function getLatestVersionOfCli({
929144
929150
  if (cliEnvironment.packageName !== "fern-api" || cliEnvironment.packageVersion === "0.0.0") {
929145
929151
  return cliEnvironment.packageVersion;
929146
929152
  }
929147
- return latestVersion(cliEnvironment.packageName, {
929148
- version: includePreReleases ? "prerelease" : "latest"
929149
- });
929153
+ try {
929154
+ return await latestVersion(cliEnvironment.packageName, {
929155
+ version: includePreReleases ? "prerelease" : "latest"
929156
+ });
929157
+ } catch (error50) {
929158
+ throw new CliError({
929159
+ message: `Failed to resolve latest CLI version: ${error50 instanceof Error ? error50.message : String(error50)}`,
929160
+ code: CliError.Code.NetworkError
929161
+ });
929162
+ }
929150
929163
  }
929151
929164
 
929152
929165
  // src/cli-context/CliContext.ts
@@ -929193,7 +929206,7 @@ var CliContext = class _CliContext {
929193
929206
  if (false) {
929194
929207
  this.logger.error("CLI_VERSION is not defined");
929195
929208
  }
929196
- return "4.68.4";
929209
+ return "4.68.5-1-g8e557fa8d81";
929197
929210
  }
929198
929211
  getCliName() {
929199
929212
  if (false) {
@@ -929474,7 +929487,15 @@ var CliContext = class _CliContext {
929474
929487
  * @returns Promise<string> representing the user's input
929475
929488
  */
929476
929489
  async getInput(config5) {
929477
- return await esm_default10({ message: config5.message, default: config5.default });
929490
+ try {
929491
+ return await esm_default10({ message: config5.message, default: config5.default });
929492
+ } catch (error50) {
929493
+ if (error50?.name === "ExitPromptError") {
929494
+ this.logger.info("\nCancelled by user.");
929495
+ throw new TaskAbortSignal();
929496
+ }
929497
+ throw error50;
929498
+ }
929478
929499
  }
929479
929500
  };
929480
929501
  function wrapWorkspaceNameForPrefix(workspaceName) {
@@ -929689,7 +929710,9 @@ async function getGeneratorList({
929689
929710
  try {
929690
929711
  await (0, import_promises126.writeFile)(outputLocation, generatorsListYaml);
929691
929712
  } catch (error50) {
929692
- cliContext.failAndThrow(`Could not write file to the specified location: ${outputLocation}`, error50);
929713
+ cliContext.failAndThrow(`Could not write file to the specified location: ${outputLocation}`, error50, {
929714
+ code: CliError.Code.ConfigError
929715
+ });
929693
929716
  }
929694
929717
  }
929695
929718
  function isGeneratorInModeSet(generator, modes) {
@@ -929767,7 +929790,9 @@ async function getOrganization({
929767
929790
  try {
929768
929791
  await (0, import_promises127.writeFile)(outputLocation, org);
929769
929792
  } catch (error50) {
929770
- context3.failAndThrow(`Could not write file to the specified location: ${outputLocation}`, error50);
929793
+ context3.failAndThrow(`Could not write file to the specified location: ${outputLocation}`, error50, {
929794
+ code: CliError.Code.ConfigError
929795
+ });
929771
929796
  }
929772
929797
  }
929773
929798
 
@@ -929895,7 +929920,10 @@ async function ensureMigrationsInstalled(logger4) {
929895
929920
  const packageJsonContent = await (0, import_promises128.readFile)(packageJsonPath, "utf-8");
929896
929921
  const packageJson2 = JSON.parse(packageJsonContent);
929897
929922
  if (packageJson2.main == null) {
929898
- throw new Error(`No main field found in package.json for ${MIGRATION_PACKAGE_NAME2}`);
929923
+ throw new CliError({
929924
+ message: `No main field found in package.json for ${MIGRATION_PACKAGE_NAME2}`,
929925
+ code: CliError.Code.InternalError
929926
+ });
929899
929927
  }
929900
929928
  const packageEntryPoint = (0, import_path78.join)(packageDir, packageJson2.main);
929901
929929
  const { migrations } = await import((0, import_url9.pathToFileURL)(packageEntryPoint).href);
@@ -929968,9 +929996,10 @@ function filterMigrations(params2) {
929968
929996
  const aVersion = import_semver16.default.parse(a10.version);
929969
929997
  const bVersion = import_semver16.default.parse(b19.version);
929970
929998
  if (aVersion == null || bVersion == null) {
929971
- throw new Error(
929972
- `Internal error: Invalid migration version found during sort. Version A: ${a10.version}, Version B: ${b19.version}. This should not happen as invalid versions are filtered out.`
929973
- );
929999
+ throw new CliError({
930000
+ message: `Internal error: Invalid migration version found during sort. Version A: ${a10.version}, Version B: ${b19.version}. This should not happen as invalid versions are filtered out.`,
930001
+ code: CliError.Code.InternalError
930002
+ });
929974
930003
  }
929975
930004
  return import_semver16.default.compare(aVersion, bVersion);
929976
930005
  });
@@ -929988,15 +930017,16 @@ function runMigrations(params2) {
929988
930017
  appliedVersions.push(migration23.version);
929989
930018
  } catch (error50) {
929990
930019
  const errorMessage = extractErrorMessage(error50);
929991
- throw new Error(
929992
- `Failed to apply migration for version ${migration23.version}.
930020
+ throw new CliError({
930021
+ message: `Failed to apply migration for version ${migration23.version}.
929993
930022
 
929994
930023
  Reason: ${errorMessage}
929995
930024
 
929996
930025
  This migration was attempting to update your generator configuration. The upgrade has been halted to prevent partial or invalid changes.
929997
930026
 
929998
- Please report this issue at: https://github.com/fern-api/fern/issues`
929999
- );
930027
+ Please report this issue at: https://github.com/fern-api/fern/issues`,
930028
+ code: CliError.Code.InternalError
930029
+ });
930000
930030
  }
930001
930031
  }
930002
930032
  return {
@@ -930016,13 +930046,14 @@ function isValidGeneratorConfig(config5) {
930016
930046
  async function loadAndRunMigrations(params2) {
930017
930047
  const { generatorName, from: from4, to: to8, config: config5, logger: logger4 } = params2;
930018
930048
  if (!isValidGeneratorConfig(config5)) {
930019
- throw new Error(
930020
- `Invalid generator configuration for ${generatorName}.
930049
+ throw new CliError({
930050
+ message: `Invalid generator configuration for ${generatorName}.
930021
930051
 
930022
930052
  The generator configuration must be an object with either a 'name' property or an 'image' property, but the current configuration does not match this structure. This may indicate a malformed generators.yml file.
930023
930053
 
930024
- Please check your generators.yml file and ensure the generator is properly configured.`
930025
- );
930054
+ Please check your generators.yml file and ensure the generator is properly configured.`,
930055
+ code: CliError.Code.InternalError
930056
+ });
930026
930057
  }
930027
930058
  const typedConfig = config5;
930028
930059
  const migrationModule = await loadMigrationModule({ generatorName, logger: logger4 });
@@ -930087,7 +930118,9 @@ async function loadAndUpdateGenerators({
930087
930118
  };
930088
930119
  }
930089
930120
  if (!import_yaml6.default.isMap(generatorGroups)) {
930090
- context3.failAndThrow(`Expected 'groups' to be a map in ${import_path79.default.relative(process.cwd(), filepath)}`);
930121
+ context3.failAndThrow(`Expected 'groups' to be a map in ${import_path79.default.relative(process.cwd(), filepath)}`, void 0, {
930122
+ code: CliError.Code.ParseError
930123
+ });
930091
930124
  return {
930092
930125
  updatedConfiguration: void 0,
930093
930126
  skippedMajorUpgrades: [],
@@ -930106,7 +930139,9 @@ async function loadAndUpdateGenerators({
930106
930139
  const group = groupBlock.value;
930107
930140
  if (!import_yaml6.default.isMap(group)) {
930108
930141
  context3.failAndThrow(
930109
- `Expected group ${groupName} to be a map in ${import_path79.default.relative(process.cwd(), filepath)}`
930142
+ `Expected group ${groupName} to be a map in ${import_path79.default.relative(process.cwd(), filepath)}`,
930143
+ void 0,
930144
+ { code: CliError.Code.ConfigError }
930110
930145
  );
930111
930146
  continue;
930112
930147
  }
@@ -930117,7 +930152,9 @@ async function loadAndUpdateGenerators({
930117
930152
  const generators = group.get("generators");
930118
930153
  if (!import_yaml6.default.isSeq(generators)) {
930119
930154
  context3.failAndThrow(
930120
- `Expected group ${groupName} to have a 'generators' key in ${import_path79.default.relative(process.cwd(), filepath)}`
930155
+ `Expected group ${groupName} to have a 'generators' key in ${import_path79.default.relative(process.cwd(), filepath)}`,
930156
+ void 0,
930157
+ { code: CliError.Code.ConfigError }
930121
930158
  );
930122
930159
  continue;
930123
930160
  }
@@ -930125,7 +930162,9 @@ async function loadAndUpdateGenerators({
930125
930162
  for (const generator of generators.items) {
930126
930163
  if (!import_yaml6.default.isMap(generator)) {
930127
930164
  context3.failAndThrow(
930128
- `Expected generator in group ${groupName} to be a map in ${import_path79.default.relative(process.cwd(), filepath)}`
930165
+ `Expected generator in group ${groupName} to be a map in ${import_path79.default.relative(process.cwd(), filepath)}`,
930166
+ void 0,
930167
+ { code: CliError.Code.VersionError }
930129
930168
  );
930130
930169
  }
930131
930170
  if (generator.get("image") != null) {
@@ -930659,7 +930698,9 @@ function addGeneratorCommands(cli, cliContext) {
930659
930698
  if (generator == null) {
930660
930699
  const maybeApiFilter = argv.api ? ` for API ${argv.api}` : "";
930661
930700
  cliContext.failAndThrow(
930662
- `Generator ${argv.generator}, in group ${argv.group}${maybeApiFilter} was not found.`
930701
+ `Generator ${argv.generator}, in group ${argv.group}${maybeApiFilter} was not found.`,
930702
+ void 0,
930703
+ { code: CliError.Code.ConfigError }
930663
930704
  );
930664
930705
  }
930665
930706
  const generatorMetadata = {};
@@ -930703,7 +930744,8 @@ function addGeneratorCommands(cli, cliContext) {
930703
930744
  } catch (error50) {
930704
930745
  cliContext.failAndThrow(
930705
930746
  `Could not write file to the specified location: ${argv.output}`,
930706
- error50
930747
+ error50,
930748
+ { code: CliError.Code.ConfigError }
930707
930749
  );
930708
930750
  }
930709
930751
  }
@@ -930780,7 +930822,9 @@ async function diff({
930780
930822
  const bump = bumpOrUndefined ?? "patch";
930781
930823
  const nextVersion = import_semver18.default.inc(fromVersion, bump);
930782
930824
  if (!nextVersion) {
930783
- context3.failWithoutThrowing(`Invalid current version: ${fromVersion}`);
930825
+ context3.failWithoutThrowing(`Invalid current version: ${fromVersion}`, void 0, {
930826
+ code: CliError.Code.VersionError
930827
+ });
930784
930828
  throw new TaskAbortSignal();
930785
930829
  }
930786
930830
  return { bump, nextVersion, errors: errors4 };
@@ -930792,13 +930836,27 @@ async function readIr({
930792
930836
  }) {
930793
930837
  const absoluteFilepath = AbsoluteFilePath2.of(resolve6(cwd(), filepath));
930794
930838
  if (!await doesPathExist(absoluteFilepath, "file")) {
930795
- context3.failWithoutThrowing(`File not found: ${absoluteFilepath}`);
930839
+ context3.failWithoutThrowing(`File not found: ${absoluteFilepath}`, void 0, {
930840
+ code: CliError.Code.ConfigError
930841
+ });
930842
+ throw new TaskAbortSignal();
930843
+ }
930844
+ let ir15;
930845
+ try {
930846
+ ir15 = await streamObjectFromFile(absoluteFilepath);
930847
+ } catch (error50) {
930848
+ context3.failWithoutThrowing(
930849
+ `Failed to parse IR file ${absoluteFilepath}: ${error50 instanceof Error ? error50.message : String(error50)}`,
930850
+ error50,
930851
+ { code: CliError.Code.ParseError }
930852
+ );
930796
930853
  throw new TaskAbortSignal();
930797
930854
  }
930798
- const ir15 = await streamObjectFromFile(absoluteFilepath);
930799
930855
  const parsed = serialization_exports2.IntermediateRepresentation.parse(ir15);
930800
930856
  if (!parsed.ok) {
930801
- context3.failWithoutThrowing(`Invalid --${flagName}; expected a filepath containing a valid IR`);
930857
+ context3.failWithoutThrowing(`Invalid --${flagName}; expected a filepath containing a valid IR`, void 0, {
930858
+ code: CliError.Code.ParseError
930859
+ });
930802
930860
  throw new TaskAbortSignal();
930803
930861
  }
930804
930862
  return parsed.value;
@@ -930864,7 +930922,9 @@ function diffGeneratorVersions(context3, generatorVersions) {
930864
930922
  errors: errors4
930865
930923
  };
930866
930924
  } catch (error50) {
930867
- context3.failWithoutThrowing(`Error diffing generator versions ${from4} and ${to8}: ${error50}`);
930925
+ context3.failWithoutThrowing(`Error diffing generator versions ${from4} and ${to8}: ${error50}`, void 0, {
930926
+ code: CliError.Code.InternalError
930927
+ });
930868
930928
  throw new TaskAbortSignal();
930869
930929
  }
930870
930930
  }
@@ -930894,7 +930954,7 @@ async function collectDocsWorkspaceViolations({
930894
930954
  }) {
930895
930955
  if (workspace.config.settings?.substituteEnvVars) {
930896
930956
  workspace.config = replaceEnvVariables(workspace.config, {
930897
- onError: (e6) => context3.failAndThrow(e6)
930957
+ onError: (e6) => context3.failAndThrow(e6, void 0, { code: CliError.Code.ValidationError })
930898
930958
  });
930899
930959
  }
930900
930960
  const startTime = performance.now();
@@ -930929,7 +930989,7 @@ async function validateDocsWorkspaceWithoutExiting({
930929
930989
  }) {
930930
930990
  if (workspace.config.settings?.substituteEnvVars) {
930931
930991
  workspace.config = replaceEnvVariables(workspace.config, {
930932
- onError: (e6) => context3.failAndThrow(e6)
930992
+ onError: (e6) => context3.failAndThrow(e6, void 0, { code: CliError.Code.ValidationError })
930933
930993
  });
930934
930994
  }
930935
930995
  const startTime = performance.now();
@@ -930974,7 +931034,7 @@ async function validateDocsWorkspaceAndLogIssues({
930974
931034
  excludeRules
930975
931035
  });
930976
931036
  if (hasErrors) {
930977
- context3.failAndThrow();
931037
+ context3.failAndThrow(void 0, void 0, { code: CliError.Code.ValidationError });
930978
931038
  }
930979
931039
  }
930980
931040
 
@@ -931108,7 +931168,10 @@ async function getSlugForFiles({
931108
931168
  });
931109
931169
  if (!response.ok) {
931110
931170
  const errorText = await response.text();
931111
- throw new Error(`Failed to get slugs for files: ${response.status} ${response.statusText} - ${errorText}`);
931171
+ throw new CliError({
931172
+ message: `Failed to get slugs for files: ${response.status} ${response.statusText} - ${errorText}`,
931173
+ code: CliError.Code.InternalError
931174
+ });
931112
931175
  }
931113
931176
  return await response.json();
931114
931177
  }
@@ -931357,11 +931420,11 @@ async function generateComparisons({
931357
931420
  }
931358
931421
  function getProductionUrlInfo(docsConfig) {
931359
931422
  if (docsConfig.instances == null || docsConfig.instances.length === 0) {
931360
- throw new Error("No docs instances configured in docs.yml");
931423
+ throw new CliError({ message: "No docs instances configured in docs.yml", code: CliError.Code.InternalError });
931361
931424
  }
931362
931425
  const firstInstance = docsConfig.instances[0];
931363
931426
  if (firstInstance == null) {
931364
- throw new Error("No docs instances configured in docs.yml");
931427
+ throw new CliError({ message: "No docs instances configured in docs.yml", code: CliError.Code.InternalError });
931365
931428
  }
931366
931429
  const instanceUrl = firstInstance["custom-domain"] ?? firstInstance.url;
931367
931430
  let normalizedUrl = instanceUrl;
@@ -931386,14 +931449,18 @@ async function docsDiff({
931386
931449
  }) {
931387
931450
  const docsWorkspace = project.docsWorkspaces;
931388
931451
  if (docsWorkspace == null) {
931389
- cliContext.failAndThrow("No docs workspace found. Make sure you have a docs.yml file.");
931452
+ cliContext.failAndThrow("No docs workspace found. Make sure you have a docs.yml file.", void 0, {
931453
+ code: CliError.Code.ConfigError
931454
+ });
931390
931455
  return { diffs: [] };
931391
931456
  }
931392
931457
  const token = await cliContext.runTask(async (context3) => {
931393
931458
  return askToLogin(context3);
931394
931459
  });
931395
931460
  if (token == null) {
931396
- cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.");
931461
+ cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.", void 0, {
931462
+ code: CliError.Code.AuthError
931463
+ });
931397
931464
  return { diffs: [] };
931398
931465
  }
931399
931466
  const fernToken = process.env.FERN_TOKEN ?? token.value;
@@ -935838,7 +935905,7 @@ function createLibraryDocsClient({ token }) {
935838
935905
  });
935839
935906
  if (!response.ok) {
935840
935907
  const text9 = await response.text().catch(() => "");
935841
- throw new Error(`HTTP ${response.status}: ${text9}`);
935908
+ throw new CliError({ message: `HTTP ${response.status}: ${text9}`, code: CliError.Code.NetworkError });
935842
935909
  }
935843
935910
  return await response.json();
935844
935911
  }
@@ -935862,21 +935929,27 @@ var POLL_TIMEOUT_MS = 3 * 60 * 1e3;
935862
935929
  async function generateLibraryDocs({ project, cliContext, library }) {
935863
935930
  const docsWorkspace = project.docsWorkspaces;
935864
935931
  if (docsWorkspace == null) {
935865
- cliContext.failAndThrow("No docs workspace found. Make sure you have a docs.yml file.");
935932
+ cliContext.failAndThrow("No docs workspace found. Make sure you have a docs.yml file.", void 0, {
935933
+ code: CliError.Code.ConfigError
935934
+ });
935866
935935
  return;
935867
935936
  }
935868
935937
  const rawConfig = docsWorkspace.config;
935869
935938
  const libraries = rawConfig.libraries;
935870
935939
  if (libraries == null || Object.keys(libraries).length === 0) {
935871
935940
  cliContext.failAndThrow(
935872
- "No libraries configured in docs.yml. Add a `libraries` section to configure library documentation."
935941
+ "No libraries configured in docs.yml. Add a `libraries` section to configure library documentation.",
935942
+ void 0,
935943
+ { code: CliError.Code.ConfigError }
935873
935944
  );
935874
935945
  return;
935875
935946
  }
935876
935947
  const librariesToGenerate = library != null ? { [library]: libraries[library] } : libraries;
935877
935948
  if (library != null && libraries[library] == null) {
935878
935949
  cliContext.failAndThrow(
935879
- `Library '${library}' not found in docs.yml. Available libraries: ${Object.keys(libraries).join(", ")}`
935950
+ `Library '${library}' not found in docs.yml. Available libraries: ${Object.keys(libraries).join(", ")}`,
935951
+ void 0,
935952
+ { code: CliError.Code.ConfigError }
935880
935953
  );
935881
935954
  return;
935882
935955
  }
@@ -935884,7 +935957,9 @@ async function generateLibraryDocs({ project, cliContext, library }) {
935884
935957
  return askToLogin(context3);
935885
935958
  });
935886
935959
  if (token == null) {
935887
- cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.");
935960
+ cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.", void 0, {
935961
+ code: CliError.Code.AuthError
935962
+ });
935888
935963
  return;
935889
935964
  }
935890
935965
  const orgId = project.config.organization;
@@ -935896,7 +935971,9 @@ async function generateLibraryDocs({ project, cliContext, library }) {
935896
935971
  }
935897
935972
  if (!isGitLibraryInput2(config5.input)) {
935898
935973
  context3.failAndThrow(
935899
- `Library '${name2}' uses 'path' input which is not yet supported. Please use 'git' input.`
935974
+ `Library '${name2}' uses 'path' input which is not yet supported. Please use 'git' input.`,
935975
+ void 0,
935976
+ { code: CliError.Code.ConfigError }
935900
935977
  );
935901
935978
  return false;
935902
935979
  }
@@ -935929,7 +936006,9 @@ async function generateSingleLibrary({
935929
936006
  return context3.runInteractiveTask({ name: name2 }, async (interactiveTaskContext) => {
935930
936007
  if (config5.config?.doxyfile != null && config5.lang !== "cpp") {
935931
936008
  return interactiveTaskContext.failAndThrow(
935932
- `Library '${name2}': 'doxyfile' config is only valid for lang: cpp`
936009
+ `Library '${name2}': 'doxyfile' config is only valid for lang: cpp`,
936010
+ void 0,
936011
+ { code: CliError.Code.ConfigError }
935933
936012
  );
935934
936013
  }
935935
936014
  let doxyfileContent;
@@ -935939,13 +936018,19 @@ async function generateSingleLibrary({
935939
936018
  doxyfileContent = await (0, import_promises133.readFile)(doxyfilePath, "utf-8");
935940
936019
  } catch {
935941
936020
  return interactiveTaskContext.failAndThrow(
935942
- `Library '${name2}': Could not read Doxyfile at '${config5.config.doxyfile}' (resolved to ${doxyfilePath})`
936021
+ `Library '${name2}': Could not read Doxyfile at '${config5.config.doxyfile}' (resolved to ${doxyfilePath})`,
936022
+ void 0,
936023
+ { code: CliError.Code.ConfigError }
935943
936024
  );
935944
936025
  }
935945
936026
  }
935946
936027
  const language = config5.lang === "python" ? "PYTHON" : config5.lang === "cpp" ? "CPP" : void 0;
935947
936028
  if (language == null) {
935948
- return interactiveTaskContext.failAndThrow(`Library '${name2}': unsupported language '${config5.lang}'`);
936029
+ return interactiveTaskContext.failAndThrow(
936030
+ `Library '${name2}': unsupported language '${config5.lang}'`,
936031
+ void 0,
936032
+ { code: CliError.Code.ConfigError }
936033
+ );
935949
936034
  }
935950
936035
  const client3 = createLibraryDocsClient({ token: token.value });
935951
936036
  interactiveTaskContext.logger.debug(`Starting generation for library '${name2}' from ${gitInput.git}`);
@@ -935985,7 +936070,11 @@ To include in your docs navigation, add to docs.yml:
935985
936070
  });
935986
936071
  interactiveTaskContext.logger.debug(`Generated ${generateResult.pageCount} pages at ${resolvedOutputPath}`);
935987
936072
  } else {
935988
- return interactiveTaskContext.failAndThrow(`Library '${name2}': unsupported language '${config5.lang}'`);
936073
+ return interactiveTaskContext.failAndThrow(
936074
+ `Library '${name2}': unsupported language '${config5.lang}'`,
936075
+ void 0,
936076
+ { code: CliError.Code.ConfigError }
936077
+ );
935989
936078
  }
935990
936079
  });
935991
936080
  }
@@ -936007,7 +936096,9 @@ async function startGeneration(client3, context3, opts) {
936007
936096
  return result.jobId;
936008
936097
  } catch (error50) {
936009
936098
  return context3.failAndThrow(
936010
- `Failed to start generation for library '${opts.name}': ${extractErrorMessage(error50)}`
936099
+ `Failed to start generation for library '${opts.name}': ${extractErrorMessage(error50)}`,
936100
+ error50,
936101
+ { code: CliError.Code.NetworkError }
936011
936102
  );
936012
936103
  }
936013
936104
  }
@@ -936020,7 +936111,9 @@ async function pollForCompletion(client3, jobId, libraryName, context3) {
936020
936111
  status = await client3.getLibraryDocsGenerationStatus({ jobId });
936021
936112
  } catch (error50) {
936022
936113
  return context3.failAndThrow(
936023
- `Failed to check generation status for library '${libraryName}': ${extractErrorMessage(error50)}`
936114
+ `Failed to check generation status for library '${libraryName}': ${extractErrorMessage(error50)}`,
936115
+ error50,
936116
+ { code: CliError.Code.NetworkError }
936024
936117
  );
936025
936118
  }
936026
936119
  switch (status.status) {
@@ -936035,15 +936128,23 @@ async function pollForCompletion(client3, jobId, libraryName, context3) {
936035
936128
  return;
936036
936129
  case "FAILED":
936037
936130
  return context3.failAndThrow(
936038
- `Generation failed for library '${libraryName}': ${status.error?.message ?? "Unknown error"} (${status.error?.code ?? "UNKNOWN"})`
936131
+ `Generation failed for library '${libraryName}': ${status.error?.message ?? "Unknown error"} (${status.error?.code ?? "UNKNOWN"})`,
936132
+ void 0,
936133
+ { code: CliError.Code.InternalError }
936039
936134
  );
936040
936135
  default:
936041
936136
  return context3.failAndThrow(
936042
- `Unexpected generation status for library '${libraryName}': ${status.status}`
936137
+ `Unexpected generation status for library '${libraryName}': ${status.status}`,
936138
+ void 0,
936139
+ { code: CliError.Code.InternalError }
936043
936140
  );
936044
936141
  }
936045
936142
  }
936046
- return context3.failAndThrow(`Generation timed out for library '${libraryName}' after ${POLL_TIMEOUT_MS / 1e3}s`);
936143
+ return context3.failAndThrow(
936144
+ `Generation timed out for library '${libraryName}' after ${POLL_TIMEOUT_MS / 1e3}s`,
936145
+ void 0,
936146
+ { code: CliError.Code.NetworkError }
936147
+ );
936047
936148
  }
936048
936149
  async function downloadIr(client3, jobId, libraryName, language, context3) {
936049
936150
  let resultUrl;
@@ -936052,29 +936153,39 @@ async function downloadIr(client3, jobId, libraryName, language, context3) {
936052
936153
  resultUrl = result.resultUrl;
936053
936154
  } catch (error50) {
936054
936155
  return context3.failAndThrow(
936055
- `Failed to fetch generation result for library '${libraryName}': ${extractErrorMessage(error50)}`
936156
+ `Failed to fetch generation result for library '${libraryName}': ${extractErrorMessage(error50)}`,
936157
+ error50,
936158
+ { code: CliError.Code.NetworkError }
936056
936159
  );
936057
936160
  }
936058
936161
  context3.logger.debug(`Fetching IR from ${resultUrl}`);
936059
936162
  const irFetchResponse = await fetch(resultUrl);
936060
936163
  if (!irFetchResponse.ok) {
936061
936164
  return context3.failAndThrow(
936062
- `Failed to download IR for library '${libraryName}': HTTP ${irFetchResponse.status}`
936165
+ `Failed to download IR for library '${libraryName}': HTTP ${irFetchResponse.status}`,
936166
+ void 0,
936167
+ { code: CliError.Code.NetworkError }
936063
936168
  );
936064
936169
  }
936065
936170
  const irWrapper = await irFetchResponse.json();
936066
936171
  const ir15 = irWrapper.ir;
936067
936172
  if (ir15 == null) {
936068
- return context3.failAndThrow(`IR is empty for library '${libraryName}'`);
936173
+ return context3.failAndThrow(`IR is empty for library '${libraryName}'`, void 0, {
936174
+ code: CliError.Code.InternalError
936175
+ });
936069
936176
  }
936070
936177
  if (language === "CPP") {
936071
936178
  if (ir15.rootNamespace == null) {
936072
- return context3.failAndThrow(`IR has no rootNamespace for C++ library '${libraryName}'`);
936179
+ return context3.failAndThrow(`IR has no rootNamespace for C++ library '${libraryName}'`, void 0, {
936180
+ code: CliError.Code.InternalError
936181
+ });
936073
936182
  }
936074
936183
  context3.logger.debug(`Downloaded C++ IR for '${libraryName}'`);
936075
936184
  } else {
936076
936185
  if (ir15.rootModule == null) {
936077
- return context3.failAndThrow(`IR has no rootModule for library '${libraryName}'`);
936186
+ return context3.failAndThrow(`IR has no rootModule for library '${libraryName}'`, void 0, {
936187
+ code: CliError.Code.InternalError
936188
+ });
936078
936189
  }
936079
936190
  context3.logger.debug(`Downloaded IR with ${Object.keys(ir15.rootModule).length} top-level keys`);
936080
936191
  }
@@ -936105,7 +936216,9 @@ async function deleteDocsPreview({
936105
936216
  `Invalid preview URL: ${previewUrl}
936106
936217
  Only preview sites can be deleted with this command.
936107
936218
  Preview URLs follow the pattern: {org}-preview-{hash}.docs.buildwithfern.com
936108
- Example: acme-preview-abc123.docs.buildwithfern.com`
936219
+ Example: acme-preview-abc123.docs.buildwithfern.com`,
936220
+ void 0,
936221
+ { code: CliError.Code.ConfigError }
936109
936222
  );
936110
936223
  return;
936111
936224
  }
@@ -936113,7 +936226,9 @@ Example: acme-preview-abc123.docs.buildwithfern.com`
936113
936226
  return askToLogin(context3);
936114
936227
  });
936115
936228
  if (token == null) {
936116
- cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.");
936229
+ cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.", void 0, {
936230
+ code: CliError.Code.AuthError
936231
+ });
936117
936232
  return;
936118
936233
  }
936119
936234
  await cliContext.runTask(async (context3) => {
@@ -936128,12 +936243,18 @@ Example: acme-preview-abc123.docs.buildwithfern.com`
936128
936243
  switch (deleteResponse.error.error) {
936129
936244
  case "UnauthorizedError":
936130
936245
  return context3.failAndThrow(
936131
- "You do not have permissions to delete this preview site. Reach out to support@buildwithfern.com"
936246
+ "You do not have permissions to delete this preview site. Reach out to support@buildwithfern.com",
936247
+ void 0,
936248
+ { code: CliError.Code.NetworkError }
936132
936249
  );
936133
936250
  case "DocsNotFoundError":
936134
- return context3.failAndThrow(`Preview site not found: ${previewUrl}`);
936251
+ return context3.failAndThrow(`Preview site not found: ${previewUrl}`, void 0, {
936252
+ code: CliError.Code.ConfigError
936253
+ });
936135
936254
  default:
936136
- return context3.failAndThrow(`Failed to delete preview site: ${previewUrl}`, deleteResponse.error);
936255
+ return context3.failAndThrow(`Failed to delete preview site: ${previewUrl}`, deleteResponse.error, {
936256
+ code: CliError.Code.NetworkError
936257
+ });
936137
936258
  }
936138
936259
  }
936139
936260
  });
@@ -936149,7 +936270,9 @@ async function listDocsPreview({
936149
936270
  return askToLogin(context3);
936150
936271
  });
936151
936272
  if (token == null) {
936152
- cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.");
936273
+ cliContext.failAndThrow("Failed to authenticate. Please run 'fern login' first.", void 0, {
936274
+ code: CliError.Code.AuthError
936275
+ });
936153
936276
  return;
936154
936277
  }
936155
936278
  await cliContext.runTask(async (context3) => {
@@ -936164,14 +936287,17 @@ async function listDocsPreview({
936164
936287
  switch (listResponse.error.error) {
936165
936288
  case "UnauthorizedError":
936166
936289
  return context3.failAndThrow(
936167
- "Unauthorized to list preview deployments. Please run 'fern login' to refresh your credentials, or set the FERN_TOKEN environment variable."
936290
+ "Unauthorized to list preview deployments. Please run 'fern login' to refresh your credentials, or set the FERN_TOKEN environment variable.",
936291
+ void 0,
936292
+ { code: CliError.Code.NetworkError }
936168
936293
  );
936169
936294
  default: {
936170
936295
  const errorContent = listResponse.error.content != null && typeof listResponse.error.content === "object" && "body" in listResponse.error.content ? listResponse.error.content.body : listResponse.error.content;
936171
936296
  context3.logger.debug(`Error fetching preview deployments: ${JSON.stringify(errorContent)}`);
936172
936297
  return context3.failAndThrow(
936173
936298
  "Failed to fetch preview deployments. Please ensure you are logged in with 'fern login' or have FERN_TOKEN set, then try again.",
936174
- listResponse.error
936299
+ listResponse.error,
936300
+ { code: CliError.Code.NetworkError }
936175
936301
  );
936176
936302
  }
936177
936303
  }
@@ -936935,11 +937061,15 @@ async function downgrade({
936935
937061
  targetVersion
936936
937062
  }) {
936937
937063
  if (!targetVersion) {
936938
- return cliContext.failAndThrow("Please specify a version to downgrade to using --version");
937064
+ return cliContext.failAndThrow("Please specify a version to downgrade to using --version", void 0, {
937065
+ code: CliError.Code.ConfigError
937066
+ });
936939
937067
  }
936940
937068
  const fernDirectory = await getFernDirectory();
936941
937069
  if (fernDirectory == null) {
936942
- return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
937070
+ return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, void 0, {
937071
+ code: CliError.Code.ConfigError
937072
+ });
936943
937073
  }
936944
937074
  const projectConfig = await cliContext.runTask(
936945
937075
  (context3) => loadProjectConfig({ directory: fernDirectory, context: context3 })
@@ -937017,7 +937147,10 @@ function convertType4(typeDeclaration2, ir15) {
937017
937147
  return convertUndiscriminatedUnion2({ undiscriminatedUnionDeclaration, docs });
937018
937148
  },
937019
937149
  _other: () => {
937020
- throw new Error("Encountered unknown type: " + shape.type);
937150
+ throw new CliError({
937151
+ message: "Encountered unknown type: " + shape.type,
937152
+ code: CliError.Code.InternalError
937153
+ });
937021
937154
  }
937022
937155
  });
937023
937156
  return {
@@ -937086,7 +937219,10 @@ function convertUnion({
937086
937219
  required: [getWireValue(unionTypeDeclaration.discriminant)]
937087
937220
  }),
937088
937221
  _other: () => {
937089
- throw new Error("Unknown SingleUnionTypeProperties: " + singleUnionType.shape.propertiesType);
937222
+ throw new CliError({
937223
+ message: "Unknown SingleUnionTypeProperties: " + singleUnionType.shape.propertiesType,
937224
+ code: CliError.Code.InternalError
937225
+ });
937090
937226
  }
937091
937227
  });
937092
937228
  });
@@ -937137,7 +937273,10 @@ function convertTypeReference4(typeReference2) {
937137
937273
  return {};
937138
937274
  },
937139
937275
  _other: () => {
937140
- throw new Error("Encountered unknown typeReference: " + typeReference2.type);
937276
+ throw new CliError({
937277
+ message: "Encountered unknown typeReference: " + typeReference2.type,
937278
+ code: CliError.Code.InternalError
937279
+ });
937141
937280
  }
937142
937281
  });
937143
937282
  }
@@ -937222,7 +937361,10 @@ function convertPrimitiveType3(primitiveType2) {
937222
937361
  };
937223
937362
  },
937224
937363
  _other: () => {
937225
- throw new Error("Encountered unknown primitiveType: " + primitiveType2.v1);
937364
+ throw new CliError({
937365
+ message: "Encountered unknown primitiveType: " + primitiveType2.v1,
937366
+ code: CliError.Code.InternalError
937367
+ });
937226
937368
  }
937227
937369
  }) ?? {};
937228
937370
  }
@@ -937312,7 +937454,10 @@ function convertPrimitiveType3(primitiveType2) {
937312
937454
  };
937313
937455
  },
937314
937456
  _other: () => {
937315
- throw new Error("Encountered unknown primitiveType: " + primitiveType2.v2);
937457
+ throw new CliError({
937458
+ message: "Encountered unknown primitiveType: " + primitiveType2.v2,
937459
+ code: CliError.Code.InternalError
937460
+ });
937316
937461
  }
937317
937462
  });
937318
937463
  }
@@ -937372,7 +937517,10 @@ function convertContainerType3(containerType) {
937372
937517
  });
937373
937518
  },
937374
937519
  _other: () => {
937375
- throw new Error("Encountered unknown containerType: " + containerType.type);
937520
+ throw new CliError({
937521
+ message: "Encountered unknown containerType: " + containerType.type,
937522
+ code: CliError.Code.InternalError
937523
+ });
937376
937524
  }
937377
937525
  });
937378
937526
  }
@@ -937491,7 +937639,10 @@ function convertServices2({
937491
937639
  });
937492
937640
  const pathsObject = paths[fullPath] ??= {};
937493
937641
  if (pathsObject[convertedHttpMethod] != null) {
937494
- throw new Error(`Duplicate ${convertedHttpMethod} endpoint at ${fullPath}`);
937642
+ throw new CliError({
937643
+ message: `Duplicate ${convertedHttpMethod} endpoint at ${fullPath}`,
937644
+ code: CliError.Code.ConfigError
937645
+ });
937495
937646
  }
937496
937647
  pathsObject[convertedHttpMethod] = operationObject;
937497
937648
  });
@@ -937576,12 +937727,15 @@ function convertHttpEndpoint4({
937576
937727
  if (httpEndpoint.baseUrl != null) {
937577
937728
  const baseUrlId = httpEndpoint.baseUrl;
937578
937729
  if (environments2?.environments.type !== "multipleBaseUrls") {
937579
- throw new Error("baseUrl is defined environments are not multipleBaseUrls");
937730
+ throw new CliError({
937731
+ message: "baseUrl is defined environments are not multipleBaseUrls",
937732
+ code: CliError.Code.InternalError
937733
+ });
937580
937734
  }
937581
937735
  operationObject.servers = environments2.environments.environments.map((environment2) => {
937582
937736
  const url3 = environment2.urls[baseUrlId];
937583
937737
  if (url3 == null) {
937584
- throw new Error("No URL defined for " + baseUrlId);
937738
+ throw new CliError({ message: "No URL defined for " + baseUrlId, code: CliError.Code.InternalError });
937585
937739
  }
937586
937740
  const server = { url: url3 };
937587
937741
  if (environment2.docs != null) {
@@ -937627,7 +937781,10 @@ function convertHttpMethod3(httpMethod) {
937627
937781
  return import_openapi_types3.OpenAPIV3.HttpMethods.HEAD;
937628
937782
  },
937629
937783
  _other: () => {
937630
- throw new Error("Encountered unknown http method: " + httpMethod);
937784
+ throw new CliError({
937785
+ message: "Encountered unknown http method: " + httpMethod,
937786
+ code: CliError.Code.InternalError
937787
+ });
937631
937788
  }
937632
937789
  });
937633
937790
  }
@@ -937719,7 +937876,10 @@ function convertRequestBody4({
937719
937876
  };
937720
937877
  },
937721
937878
  _other: () => {
937722
- throw new Error("Unknown FileUploadRequestProperty: " + property23.type);
937879
+ throw new CliError({
937880
+ message: "Unknown FileUploadRequestProperty: " + property23.type,
937881
+ code: CliError.Code.InternalError
937882
+ });
937723
937883
  }
937724
937884
  });
937725
937885
  return {
@@ -937747,7 +937907,10 @@ function convertRequestBody4({
937747
937907
  };
937748
937908
  },
937749
937909
  _other: () => {
937750
- throw new Error("Unknown HttpRequestBody type: " + httpRequest2.type);
937910
+ throw new CliError({
937911
+ message: "Unknown HttpRequestBody type: " + httpRequest2.type,
937912
+ code: CliError.Code.InternalError
937913
+ });
937751
937914
  }
937752
937915
  });
937753
937916
  }
@@ -937847,9 +938010,10 @@ function convertResponse3({
937847
938010
  for (const responseError of responseErrors) {
937848
938011
  const errorDeclaration = errorsByName[getErrorTypeNameKey(responseError.error)];
937849
938012
  if (errorDeclaration == null) {
937850
- throw new Error(
937851
- "Encountered undefined error declaration: " + getOriginalName(responseError.error.name)
937852
- );
938013
+ throw new CliError({
938014
+ message: "Encountered undefined error declaration: " + getOriginalName(responseError.error.name),
938015
+ code: CliError.Code.ResolutionError
938016
+ });
937853
938017
  }
937854
938018
  const responseForStatusCode = {
937855
938019
  description: responseError.docs ?? ""
@@ -937931,7 +938095,10 @@ function convertResponse3({
937931
938095
  }
937932
938096
  },
937933
938097
  _other: () => {
937934
- throw new Error("Unknown error discrimination strategy: " + errorDiscriminationStrategy.type);
938098
+ throw new CliError({
938099
+ message: "Unknown error discrimination strategy: " + errorDiscriminationStrategy.type,
938100
+ code: CliError.Code.InternalError
938101
+ });
937935
938102
  }
937936
938103
  });
937937
938104
  return responseByStatusCode;
@@ -937965,7 +938132,10 @@ function getErrorInfoByStatusCode({
937965
938132
  for (const responseError of responseErrors) {
937966
938133
  const errorDeclaration = errorsByName[getErrorTypeNameKey(responseError.error)];
937967
938134
  if (errorDeclaration == null) {
937968
- throw new Error("Encountered undefined error declaration: " + getOriginalName(responseError.error.name));
938135
+ throw new CliError({
938136
+ message: "Encountered undefined error declaration: " + getOriginalName(responseError.error.name),
938137
+ code: CliError.Code.ResolutionError
938138
+ });
937969
938139
  }
937970
938140
  const statusCode = errorDeclaration.statusCode;
937971
938141
  const statusCodeErrorInfo = errorInfoByStatusCode[statusCode];
@@ -938106,7 +938276,10 @@ function isTypeReferenceRequired({
938106
938276
  const key2 = getDeclaredTypeNameKey(typeReference2);
938107
938277
  const typeDeclaration2 = typesByName[key2];
938108
938278
  if (typeDeclaration2 == null) {
938109
- throw new Error("Encountered non-existent type: " + getOriginalName(typeReference2.name));
938279
+ throw new CliError({
938280
+ message: "Encountered non-existent type: " + getOriginalName(typeReference2.name),
938281
+ code: CliError.Code.ResolutionError
938282
+ });
938110
938283
  }
938111
938284
  if (typeDeclaration2.shape.type === "alias") {
938112
938285
  return isTypeReferenceRequired({ typeReference: typeDeclaration2.shape.aliasOf, typesByName });
@@ -938136,7 +938309,10 @@ function constructEndpointSecurity(apiAuth) {
938136
938309
  return [];
938137
938310
  },
938138
938311
  _other: () => {
938139
- throw new Error("Unknown auth scheme requirement: " + apiAuth.requirement);
938312
+ throw new CliError({
938313
+ message: "Unknown auth scheme requirement: " + apiAuth.requirement,
938314
+ code: CliError.Code.InternalError
938315
+ });
938140
938316
  }
938141
938317
  });
938142
938318
  }
@@ -938163,7 +938339,10 @@ function constructSecuritySchemes(apiAuth) {
938163
938339
  }),
938164
938340
  inferred: () => void 0,
938165
938341
  _other: () => {
938166
- throw new Error("Unknown auth scheme: " + scheme.type);
938342
+ throw new CliError({
938343
+ message: "Unknown auth scheme: " + scheme.type,
938344
+ code: CliError.Code.InternalError
938345
+ });
938167
938346
  }
938168
938347
  });
938169
938348
  if (oasScheme) {
@@ -938180,7 +938359,10 @@ function getNameForAuthScheme(authScheme) {
938180
938359
  oauth: () => "BearerAuth",
938181
938360
  header: (header) => `${getPascalCaseUnsafe(header.name)}Auth`,
938182
938361
  _other: () => {
938183
- throw new Error("Unknown auth scheme: " + authScheme.type);
938362
+ throw new CliError({
938363
+ message: "Unknown auth scheme: " + authScheme.type,
938364
+ code: CliError.Code.InternalError
938365
+ });
938184
938366
  }
938185
938367
  });
938186
938368
  }
@@ -938499,7 +938681,7 @@ async function generateWorkspace({
938499
938681
  const suggestedCommand = `fern ${currentArgs} --${GROUP_CLI_OPTION} ${name2}`;
938500
938682
  return ` \u203A ${source_default.bold(name2.padEnd(longestGroupName))} ${source_default.dim(suggestedCommand)}`;
938501
938683
  }).join("\n");
938502
- return context3.failAndThrow(message);
938684
+ return context3.failAndThrow(message, void 0, { code: CliError.Code.NetworkError });
938503
938685
  }
938504
938686
  const resolvedGroupNames = resolveGroupAlias(
938505
938687
  groupNameOrDefault,
@@ -938509,7 +938691,7 @@ async function generateWorkspace({
938509
938691
  );
938510
938692
  const { ai: ai7, replay } = workspace.generatorsConfiguration;
938511
938693
  if (!useLocalDocker && !token) {
938512
- return context3.failAndThrow("Please run fern login");
938694
+ return context3.failAndThrow("Please run fern login", void 0, { code: CliError.Code.AuthError });
938513
938695
  }
938514
938696
  await Promise.all(
938515
938697
  resolvedGroupNames.map(async (resolvedGroupName) => {
@@ -938517,7 +938699,9 @@ async function generateWorkspace({
938517
938699
  (otherGroup) => otherGroup.groupName === resolvedGroupName
938518
938700
  );
938519
938701
  if (group == null) {
938520
- return context3.failAndThrow(`Group '${resolvedGroupName}' does not exist.`);
938702
+ return context3.failAndThrow(`Group '${resolvedGroupName}' does not exist.`, void 0, {
938703
+ code: CliError.Code.ConfigError
938704
+ });
938521
938705
  }
938522
938706
  const filterResult = filterGenerators({
938523
938707
  generators: group.generators,
@@ -938526,7 +938710,7 @@ async function generateWorkspace({
938526
938710
  groupName: resolvedGroupName
938527
938711
  });
938528
938712
  if (!filterResult.ok) {
938529
- return context3.failAndThrow(filterResult.error);
938713
+ return context3.failAndThrow(filterResult.error, void 0, { code: CliError.Code.ConfigError });
938530
938714
  }
938531
938715
  group = { ...group, generators: filterResult.generators };
938532
938716
  if (lfsOverride != null) {
@@ -938595,7 +938779,9 @@ function resolveGroupAlias(groupNameOrAlias, groupAliases, availableGroups, cont
938595
938779
  for (const groupName of aliasGroups) {
938596
938780
  if (!availableGroups.includes(groupName)) {
938597
938781
  context3.failAndThrow(
938598
- `Group alias '${groupNameOrAlias}' references non-existent group '${groupName}'. Available groups: ${availableGroups.join(", ")}`
938782
+ `Group alias '${groupNameOrAlias}' references non-existent group '${groupName}'. Available groups: ${availableGroups.join(", ")}`,
938783
+ void 0,
938784
+ { code: CliError.Code.NetworkError }
938599
938785
  );
938600
938786
  }
938601
938787
  }
@@ -938607,7 +938793,9 @@ function resolveGroupAlias(groupNameOrAlias, groupAliases, availableGroups, cont
938607
938793
  const availableAliases = Object.keys(groupAliases);
938608
938794
  const suggestions = [...availableGroups, ...availableAliases];
938609
938795
  context3.failAndThrow(
938610
- `'${groupNameOrAlias}' is not a valid group or alias. Available groups: ${availableGroups.join(", ")}` + (availableAliases.length > 0 ? `. Available aliases: ${availableAliases.join(", ")}` : "")
938796
+ `'${groupNameOrAlias}' is not a valid group or alias. Available groups: ${availableGroups.join(", ")}` + (availableAliases.length > 0 ? `. Available aliases: ${availableAliases.join(", ")}` : ""),
938797
+ void 0,
938798
+ { code: CliError.Code.NetworkError }
938611
938799
  );
938612
938800
  return [];
938613
938801
  }
@@ -938742,7 +938930,7 @@ async function generateAPIWorkspaces({
938742
938930
  force
938743
938931
  );
938744
938932
  if (!shouldProceed) {
938745
- cliContext.failAndThrow("Generation cancelled");
938933
+ cliContext.failAndThrow("Generation cancelled", void 0, { code: CliError.Code.ConfigError });
938746
938934
  }
938747
938935
  }
938748
938936
  }
@@ -938921,7 +939109,10 @@ function buildPreviewDomain({ orgId, previewId }) {
938921
939109
  const availableSpace = SUBDOMAIN_LIMIT - prefix2.length;
938922
939110
  const minIdLength = 8;
938923
939111
  if (availableSpace < minIdLength) {
938924
- throw new Error(`Organization name "${orgId}" is too long to generate a valid preview URL`);
939112
+ throw new CliError({
939113
+ message: `Organization name "${orgId}" is too long to generate a valid preview URL`,
939114
+ code: CliError.Code.InternalError
939115
+ });
938925
939116
  }
938926
939117
  const truncatedId = sanitizedId.slice(0, availableSpace).replace(/-+$/, "");
938927
939118
  return `${prefix2}${truncatedId}.${DOMAIN_SUFFIX}`;
@@ -938941,7 +939132,9 @@ async function generateDocsWorkspace({
938941
939132
  }) {
938942
939133
  const docsWorkspace = project.docsWorkspaces;
938943
939134
  if (docsWorkspace == null) {
938944
- cliContext.failAndThrow("No docs.yml file found. Please make sure your project has one.");
939135
+ cliContext.failAndThrow("No docs.yml file found. Please make sure your project has one.", void 0, {
939136
+ code: CliError.Code.ConfigError
939137
+ });
938945
939138
  return;
938946
939139
  }
938947
939140
  const hasFdrOriginOverride = !!process.env["FERN_FDR_ORIGIN"] || !!process.env["OVERRIDE_FDR_ORIGIN"];
@@ -938963,7 +939156,9 @@ ${source_default.yellow("?")} Are you sure you want to continue?`,
938963
939156
  const fernToken = await getToken2();
938964
939157
  if (!fernToken) {
938965
939158
  cliContext.failAndThrow(
938966
- "No token found. Please set the FERN_TOKEN environment variable or run `fern login`."
939159
+ "No token found. Please set the FERN_TOKEN environment variable or run `fern login`.",
939160
+ void 0,
939161
+ { code: CliError.Code.AuthError }
938967
939162
  );
938968
939163
  return;
938969
939164
  }
@@ -939021,7 +939216,9 @@ ${source_default.yellow("?")} Are you sure you want to continue?`,
939021
939216
  context3.logger.error(`${error50.relativeFilepath}: ${error50.message}`);
939022
939217
  }
939023
939218
  context3.failAndThrow(
939024
- `OpenAPI spec validation failed with ${errors4.length} error${errors4.length !== 1 ? "s" : ""}. Fix the errors above before generating docs.`
939219
+ `OpenAPI spec validation failed with ${errors4.length} error${errors4.length !== 1 ? "s" : ""}. Fix the errors above before generating docs.`,
939220
+ void 0,
939221
+ { code: CliError.Code.ValidationError }
939025
939222
  );
939026
939223
  }
939027
939224
  }
@@ -939123,7 +939320,10 @@ async function generateDynamicIrForWorkspaces({
939123
939320
  disableDynamicExamples
939124
939321
  });
939125
939322
  if (intermediateRepresentation.dynamic == null) {
939126
- throw new Error("Internal error; dynamic IR was not generated");
939323
+ throw new CliError({
939324
+ message: "Internal error; dynamic IR was not generated",
939325
+ code: CliError.Code.InternalError
939326
+ });
939127
939327
  }
939128
939328
  const irOutputFilePath = import_path83.default.resolve(irFilepath);
939129
939329
  await streamObjectToFile(AbsoluteFilePath2.of(irOutputFilePath), intermediateRepresentation.dynamic);
@@ -939334,10 +939534,14 @@ async function compareOpenAPISpecs({
939334
939534
  }) {
939335
939535
  await cliContext.runTask(async (context3) => {
939336
939536
  if (!await doesPathExist(originalPath)) {
939337
- return context3.failAndThrow(`Original file does not exist: ${originalPath}`);
939537
+ return context3.failAndThrow(`Original file does not exist: ${originalPath}`, void 0, {
939538
+ code: CliError.Code.ConfigError
939539
+ });
939338
939540
  }
939339
939541
  if (!await doesPathExist(modifiedPath)) {
939340
- return context3.failAndThrow(`Modified file does not exist: ${modifiedPath}`);
939542
+ return context3.failAndThrow(`Modified file does not exist: ${modifiedPath}`, void 0, {
939543
+ code: CliError.Code.ConfigError
939544
+ });
939341
939545
  }
939342
939546
  context3.logger.info(`Comparing ${originalPath} with ${modifiedPath}`);
939343
939547
  const original = await loadSpec2(originalPath, context3);
@@ -939374,7 +939578,9 @@ async function loadSpec2(filepath, context3) {
939374
939578
  try {
939375
939579
  return jsYaml.load(contents);
939376
939580
  } catch (err) {
939377
- return context3.failAndThrow(`Failed to parse file as JSON or YAML: ${filepath}`);
939581
+ return context3.failAndThrow(`Failed to parse file as JSON or YAML: ${filepath}`, void 0, {
939582
+ code: CliError.Code.ParseError
939583
+ });
939378
939584
  }
939379
939585
  }
939380
939586
  }
@@ -939501,7 +939707,9 @@ async function readExistingOverrides(overridesFilepath, context3) {
939501
939707
  parsedOverrides = jsYaml.load(contents, { json: true });
939502
939708
  }
939503
939709
  } catch (err) {
939504
- return context3.failAndThrow(`Failed to read OpenAPI overrides from file ${overridesFilepath}`);
939710
+ return context3.failAndThrow(`Failed to read OpenAPI overrides from file ${overridesFilepath}`, void 0, {
939711
+ code: CliError.Code.ConfigError
939712
+ });
939505
939713
  }
939506
939714
  return parsedOverrides;
939507
939715
  }
@@ -939615,7 +939823,9 @@ async function installDependencies({ cliContext }) {
939615
939823
  const failed = results.filter((r23) => !r23.success);
939616
939824
  if (failed.length > 0) {
939617
939825
  context3.failAndThrow(
939618
- `Failed to install: ${failed.map((r23) => r23.name).join(", ")}. Check network connectivity and try again.`
939826
+ `Failed to install: ${failed.map((r23) => r23.name).join(", ")}. Check network connectivity and try again.`,
939827
+ void 0,
939828
+ { code: CliError.Code.EnvironmentError }
939619
939829
  );
939620
939830
  }
939621
939831
  context3.logger.info("All dependencies installed successfully.");
@@ -940054,10 +940264,14 @@ async function mergeOpenAPIWithOverrides({
940054
940264
  }) {
940055
940265
  await cliContext.runTask(async (context3) => {
940056
940266
  if (!await doesPathExist(openapiPath)) {
940057
- return context3.failAndThrow(`OpenAPI spec file does not exist: ${openapiPath}`);
940267
+ return context3.failAndThrow(`OpenAPI spec file does not exist: ${openapiPath}`, void 0, {
940268
+ code: CliError.Code.ConfigError
940269
+ });
940058
940270
  }
940059
940271
  if (!await doesPathExist(overridesPath)) {
940060
- return context3.failAndThrow(`Overrides file does not exist: ${overridesPath}`);
940272
+ return context3.failAndThrow(`Overrides file does not exist: ${overridesPath}`, void 0, {
940273
+ code: CliError.Code.ConfigError
940274
+ });
940061
940275
  }
940062
940276
  context3.logger.info(`Merging ${overridesPath} into ${openapiPath}`);
940063
940277
  const openapi = await loadYamlOrJson(openapiPath, context3);
@@ -940077,7 +940291,9 @@ async function loadYamlOrJson(filepath, context3) {
940077
940291
  try {
940078
940292
  return jsYaml.load(contents);
940079
940293
  } catch (err) {
940080
- return context3.failAndThrow(`Failed to parse file as JSON or YAML: ${filepath}`);
940294
+ return context3.failAndThrow(`Failed to parse file as JSON or YAML: ${filepath}`, void 0, {
940295
+ code: CliError.Code.ParseError
940296
+ });
940081
940297
  }
940082
940298
  }
940083
940299
  }
@@ -940666,7 +940882,9 @@ async function mockServer({
940666
940882
  command: "fern mock"
940667
940883
  });
940668
940884
  if (project.apiWorkspaces.length !== 1 || project.apiWorkspaces[0] == null) {
940669
- return cliContext.failAndThrow(`No API specified. Use the --${API_CLI_OPTION} option.`);
940885
+ return cliContext.failAndThrow(`No API specified. Use the --${API_CLI_OPTION} option.`, void 0, {
940886
+ code: CliError.Code.ConfigError
940887
+ });
940670
940888
  }
940671
940889
  const workspace = project.apiWorkspaces[0];
940672
940890
  await cliContext.runTaskForWorkspace(workspace, async (context3) => {
@@ -940724,7 +940942,9 @@ async function registerWorkspacesV1({
940724
940942
  project.apiWorkspaces.map(async (workspace) => {
940725
940943
  await cliContext.runTaskForWorkspace(workspace, async (context3) => {
940726
940944
  if (workspace instanceof OSSWorkspace) {
940727
- context3.failWithoutThrowing("Registering from OpenAPI not currently supported.");
940945
+ context3.failWithoutThrowing("Registering from OpenAPI not currently supported.", void 0, {
940946
+ code: CliError.Code.ConfigError
940947
+ });
940728
940948
  return;
940729
940949
  }
940730
940950
  const resolvedWorkspace = await workspace.toFernWorkspace({ context: context3 });
@@ -940737,10 +940957,12 @@ async function registerWorkspacesV1({
940737
940957
  if (!registerApiResponse.ok) {
940738
940958
  registerApiResponse.error._visit({
940739
940959
  versionAlreadyExists: () => {
940740
- context3.failAndThrow(`Version ${version7 ?? ""} is already registered`);
940960
+ context3.failAndThrow(`Version ${version7 ?? ""} is already registered`, void 0, {
940961
+ code: CliError.Code.VersionError
940962
+ });
940741
940963
  },
940742
940964
  _other: (value) => {
940743
- context3.failAndThrow("Failed to register", value);
940965
+ context3.failAndThrow("Failed to register", value, { code: CliError.Code.NetworkError });
940744
940966
  }
940745
940967
  });
940746
940968
  return;
@@ -940810,7 +941032,7 @@ var execAsync = (0, import_util70.promisify)(import_child_process10.exec);
940810
941032
  async function getClientRegistry(context3, project) {
940811
941033
  const workspace = project.apiWorkspaces[0];
940812
941034
  if (workspace == null) {
940813
- context3.failAndThrow("No API workspaces found in the project.");
941035
+ context3.failAndThrow("No API workspaces found in the project.", void 0, { code: CliError.Code.ConfigError });
940814
941036
  }
940815
941037
  const generatorsConfig = await loadGeneratorsConfiguration({
940816
941038
  absolutePathToWorkspace: workspace.absoluteFilePath,
@@ -940818,11 +941040,17 @@ async function getClientRegistry(context3, project) {
940818
941040
  context: context3
940819
941041
  });
940820
941042
  if (generatorsConfig == null) {
940821
- context3.failAndThrow("Could not find generators.yml in the workspace. Is this a valid fern project?");
941043
+ context3.failAndThrow(
941044
+ "Could not find generators.yml in the workspace. Is this a valid fern project?",
941045
+ void 0,
941046
+ { code: CliError.Code.ConfigError }
941047
+ );
940822
941048
  }
940823
941049
  if (generatorsConfig.ai == null) {
940824
941050
  context3.failAndThrow(
940825
- "No AI service configuration found in generators.yml. Please add an 'ai' section with provider and model."
941051
+ "No AI service configuration found in generators.yml. Please add an 'ai' section with provider and model.",
941052
+ void 0,
941053
+ { code: CliError.Code.ConfigError }
940826
941054
  );
940827
941055
  }
940828
941056
  context3.logger.debug(`Using AI service: ${generatorsConfig.ai.provider} with model ${generatorsConfig.ai.model}`);
@@ -940840,11 +941068,11 @@ async function sdkDiffCommand({
940840
941068
  From: ${fromPath}
940841
941069
  To: ${toPath5}`);
940842
941070
  if (!await doesPathExist(fromPath, "directory")) {
940843
- context3.failWithoutThrowing(`Directory not found: ${fromPath}`);
941071
+ context3.failWithoutThrowing(`Directory not found: ${fromPath}`, void 0, { code: CliError.Code.ConfigError });
940844
941072
  throw new TaskAbortSignal();
940845
941073
  }
940846
941074
  if (!await doesPathExist(toPath5, "directory")) {
940847
- context3.failWithoutThrowing(`Directory not found: ${toPath5}`);
941075
+ context3.failWithoutThrowing(`Directory not found: ${toPath5}`, void 0, { code: CliError.Code.ConfigError });
940848
941076
  throw new TaskAbortSignal();
940849
941077
  }
940850
941078
  const clientRegistry = await getClientRegistry(context3, project);
@@ -940866,7 +941094,9 @@ async function sdkDiffCommand({
940866
941094
  const diffBytes = Buffer.byteLength(gitDiff, "utf-8");
940867
941095
  if (diffBytes > MAX_RAW_DIFF_BYTES) {
940868
941096
  return context3.failAndThrow(
940869
- `Diff too large for analysis (${(diffBytes / 1e6).toFixed(1)}MB, limit ${MAX_RAW_DIFF_BYTES / 1e6}MB). Try excluding generated files or splitting the comparison.`
941097
+ `Diff too large for analysis (${(diffBytes / 1e6).toFixed(1)}MB, limit ${MAX_RAW_DIFF_BYTES / 1e6}MB). Try excluding generated files or splitting the comparison.`,
941098
+ void 0,
941099
+ { code: CliError.Code.ConfigError }
940870
941100
  );
940871
941101
  }
940872
941102
  const chunks = diffBytes > MAX_AI_DIFF_BYTES ? service.chunkDiff(gitDiff, MAX_AI_DIFF_BYTES) : [gitDiff];
@@ -940953,7 +941183,9 @@ async function sdkDiffCommand({
940953
941183
  } catch (error50) {
940954
941184
  const errorMessage = extractErrorMessage(error50);
940955
941185
  context3.failWithoutThrowing(
940956
- `Failed to analyze SDK diff. Diff stats: ${gitDiff.length.toLocaleString()} chars, ${diffSizeKB}KB, ${fileCount} files changed. ` + (cappedChunks.length > 1 ? `The diff was split into ${cappedChunks.length} chunks but analysis still failed. ` : "") + `Error: ${errorMessage}`
941186
+ `Failed to analyze SDK diff. Diff stats: ${gitDiff.length.toLocaleString()} chars, ${diffSizeKB}KB, ${fileCount} files changed. ` + (cappedChunks.length > 1 ? `The diff was split into ${cappedChunks.length} chunks but analysis still failed. ` : "") + `Error: ${errorMessage}`,
941187
+ void 0,
941188
+ { code: CliError.Code.NetworkError }
940957
941189
  );
940958
941190
  throw new TaskAbortSignal();
940959
941191
  }
@@ -940974,7 +941206,9 @@ async function generateDiff({
940974
941206
  if (typeof error50 === "object" && error50 != null && "code" in error50 && error50.code === 1 && "stdout" in error50 && typeof error50.stdout === "string") {
940975
941207
  return error50.stdout;
940976
941208
  }
940977
- return context3.failAndThrow(`Failed to generate diff: ${extractErrorMessage(error50)}`);
941209
+ return context3.failAndThrow(`Failed to generate diff: ${extractErrorMessage(error50)}`, void 0, {
941210
+ code: CliError.Code.InternalError
941211
+ });
940978
941212
  }
940979
941213
  }
940980
941214
 
@@ -941160,7 +941394,9 @@ async function sdkPreview({
941160
941394
  return askToLogin(context3);
941161
941395
  });
941162
941396
  if (token == null) {
941163
- return cliContext.failAndThrow("Authentication required. Run 'fern login' or set FERN_TOKEN.");
941397
+ return cliContext.failAndThrow("Authentication required. Run 'fern login' or set FERN_TOKEN.", void 0, {
941398
+ code: CliError.Code.AuthError
941399
+ });
941164
941400
  }
941165
941401
  const project = await loadProjectAndRegisterWorkspacesWithContext(cliContext, {
941166
941402
  commandLineApiWorkspace: apiName,
@@ -941212,19 +941448,25 @@ async function sdkPreview({
941212
941448
  const groupNameOrDefault = groupName ?? workspace.generatorsConfiguration.defaultGroup;
941213
941449
  if (groupNameOrDefault == null) {
941214
941450
  return cliContext.failAndThrow(
941215
- `No group specified. Use the --${GROUP_CLI_OPTION} option, or set "${DEFAULT_GROUP_GENERATORS_CONFIG_KEY}" in ${GENERATORS_CONFIGURATION_FILENAME}`
941451
+ `No group specified. Use the --${GROUP_CLI_OPTION} option, or set "${DEFAULT_GROUP_GENERATORS_CONFIG_KEY}" in ${GENERATORS_CONFIGURATION_FILENAME}`,
941452
+ void 0,
941453
+ { code: CliError.Code.ConfigError }
941216
941454
  );
941217
941455
  }
941218
941456
  const group = workspace.generatorsConfiguration.groups.find((g19) => g19.groupName === groupNameOrDefault);
941219
941457
  if (group == null) {
941220
941458
  return cliContext.failAndThrow(
941221
- `Group '${groupNameOrDefault}' does not exist in ${GENERATORS_CONFIGURATION_FILENAME}`
941459
+ `Group '${groupNameOrDefault}' does not exist in ${GENERATORS_CONFIGURATION_FILENAME}`,
941460
+ void 0,
941461
+ { code: CliError.Code.ConfigError }
941222
941462
  );
941223
941463
  }
941224
941464
  const generators = generatorFilter != null ? group.generators.filter((g19) => g19.name === generatorFilter) : group.generators;
941225
941465
  if (generatorFilter != null && generators.length === 0) {
941226
941466
  return cliContext.failAndThrow(
941227
- `Generator '${generatorFilter}' not found in group '${groupNameOrDefault}' in ${GENERATORS_CONFIGURATION_FILENAME}`
941467
+ `Generator '${generatorFilter}' not found in group '${groupNameOrDefault}' in ${GENERATORS_CONFIGURATION_FILENAME}`,
941468
+ void 0,
941469
+ { code: CliError.Code.ConfigError }
941228
941470
  );
941229
941471
  }
941230
941472
  const npmGenerators = generators.filter((g19) => isNpmGenerator(g19.name));
@@ -941236,14 +941478,18 @@ async function sdkPreview({
941236
941478
  }
941237
941479
  if (npmGenerators.length === 0) {
941238
941480
  return cliContext.failAndThrow(
941239
- `No supported generators found in group '${groupNameOrDefault}'. SDK preview currently only supports TypeScript/npm generators.`
941481
+ `No supported generators found in group '${groupNameOrDefault}'. SDK preview currently only supports TypeScript/npm generators.`,
941482
+ void 0,
941483
+ { code: CliError.Code.ConfigError }
941240
941484
  );
941241
941485
  }
941242
941486
  for (const generator of npmGenerators) {
941243
941487
  const originalPackageName = getPackageNameFromGeneratorConfig(generator);
941244
941488
  if (originalPackageName == null) {
941245
941489
  return cliContext.failAndThrow(
941246
- `Could not determine package name for generator '${generator.name}'. Ensure 'output.package-name' is set in ${GENERATORS_CONFIGURATION_FILENAME}.`
941490
+ `Could not determine package name for generator '${generator.name}'. Ensure 'output.package-name' is set in ${GENERATORS_CONFIGURATION_FILENAME}.`,
941491
+ void 0,
941492
+ { code: CliError.Code.ConfigError }
941247
941493
  );
941248
941494
  }
941249
941495
  const previewPackageName = toPreviewPackageName(originalPackageName, project.config.organization);
@@ -941572,7 +941818,7 @@ Resolved to: ${installationMethod.resolvedPath}`;
941572
941818
  }
941573
941819
  errorMessage += "\n\nPlease manually update using your package manager (npm, pnpm, yarn, bun, or brew).";
941574
941820
  errorMessage += "\nFor more diagnostic information, run with: FERN_LOG_LEVEL=debug fern self-update";
941575
- return cliContext.failAndThrow(errorMessage);
941821
+ return cliContext.failAndThrow(errorMessage, void 0, { code: CliError.Code.EnvironmentError });
941576
941822
  }
941577
941823
  cliContext.logger.info(`Detected installation method: ${source_default.cyan(installationMethod.type)}`);
941578
941824
  if (installationMethod.detectedPath != null) {
@@ -941584,7 +941830,9 @@ Resolved to: ${installationMethod.resolvedPath}`;
941584
941830
  const updateCommand = getUpdateCommand(installationMethod, version7);
941585
941831
  if (updateCommand.length === 0) {
941586
941832
  return cliContext.failAndThrow(
941587
- `Unable to construct update command for installation method: ${installationMethod.type}`
941833
+ `Unable to construct update command for installation method: ${installationMethod.type}`,
941834
+ void 0,
941835
+ { code: CliError.Code.EnvironmentError }
941588
941836
  );
941589
941837
  }
941590
941838
  if (installationMethod.type === "brew" && version7 != null) {
@@ -941603,7 +941851,7 @@ Resolved to: ${installationMethod.resolvedPath}`;
941603
941851
  cliContext.logger.info(`Running: ${source_default.dim(commandString)}`);
941604
941852
  const [command3, ...args] = updateCommand;
941605
941853
  if (command3 == null) {
941606
- return cliContext.failAndThrow("Invalid update command");
941854
+ return cliContext.failAndThrow("Invalid update command", void 0, { code: CliError.Code.InternalError });
941607
941855
  }
941608
941856
  const { failed, stderr } = await loggingExeca(cliContext.logger, command3, args, {
941609
941857
  doNotPipeOutput: false,
@@ -941611,7 +941859,9 @@ Resolved to: ${installationMethod.resolvedPath}`;
941611
941859
  });
941612
941860
  if (failed) {
941613
941861
  cliContext.logger.error(`Failed to update Fern CLI: ${stderr}`);
941614
- return cliContext.failAndThrow("Update failed. Please try updating manually.");
941862
+ return cliContext.failAndThrow("Update failed. Please try updating manually.", void 0, {
941863
+ code: CliError.Code.EnvironmentError
941864
+ });
941615
941865
  }
941616
941866
  cliContext.logger.info(source_default.green("\u2713 Fern CLI updated successfully!"));
941617
941867
  }
@@ -941628,10 +941878,14 @@ async function testOutput({
941628
941878
  command: "fern test"
941629
941879
  });
941630
941880
  if (testCommand == null) {
941631
- return cliContext.failAndThrow("No test command specified. Use the --command option.");
941881
+ return cliContext.failAndThrow("No test command specified. Use the --command option.", void 0, {
941882
+ code: CliError.Code.ConfigError
941883
+ });
941632
941884
  }
941633
941885
  if (project.apiWorkspaces.length !== 1 || project.apiWorkspaces[0] == null) {
941634
- return cliContext.failAndThrow(`No API specified. Use the --${API_CLI_OPTION} option.`);
941886
+ return cliContext.failAndThrow(`No API specified. Use the --${API_CLI_OPTION} option.`, void 0, {
941887
+ code: CliError.Code.ConfigError
941888
+ });
941635
941889
  }
941636
941890
  const workspace = project.apiWorkspaces[0];
941637
941891
  await cliContext.runTaskForWorkspace(workspace, async (context3) => {
@@ -941676,7 +941930,7 @@ async function testOutput({
941676
941930
  mockServer2.stop();
941677
941931
  context3.logger.error("Tests failed, Fern mock server stopping.");
941678
941932
  context3.logger.error("View test output above.");
941679
- cliContext.failAndThrow();
941933
+ cliContext.failAndThrow(void 0, void 0, { code: CliError.Code.ValidationError });
941680
941934
  }
941681
941935
  }
941682
941936
  mockServer2.stop();
@@ -941703,15 +941957,25 @@ async function generateToken({
941703
941957
  }
941704
941958
  response.error._visit({
941705
941959
  organizationNotFoundError: () => taskContext.failAndThrow(
941706
- `Failed to create token because the organization ${orgId} was not found. Please reach out to support@buildwithfern.com`
941960
+ `Failed to create token because the organization ${orgId} was not found. Please reach out to support@buildwithfern.com`,
941961
+ void 0,
941962
+ { code: CliError.Code.AuthError }
941707
941963
  ),
941708
941964
  unauthorizedError: () => taskContext.failAndThrow(
941709
- `Failed to create token because you are not in the ${orgId} organization. Please reach out to support@buildwithfern.com`
941965
+ `Failed to create token because you are not in the ${orgId} organization. Please reach out to support@buildwithfern.com`,
941966
+ void 0,
941967
+ { code: CliError.Code.AuthError }
941710
941968
  ),
941711
941969
  missingOrgPermissionsError: () => taskContext.failAndThrow(
941712
- `Failed to create token because you do not have the required permissions in the ${orgId} organization. Please reach out to support@buildwithfern.com`
941970
+ `Failed to create token because you do not have the required permissions in the ${orgId} organization. Please reach out to support@buildwithfern.com`,
941971
+ void 0,
941972
+ { code: CliError.Code.AuthError }
941713
941973
  ),
941714
- _other: () => taskContext.failAndThrow("Failed to create token. Please reach out to support@buildwithfern.com")
941974
+ _other: () => taskContext.failAndThrow(
941975
+ "Failed to create token. Please reach out to support@buildwithfern.com",
941976
+ void 0,
941977
+ { code: CliError.Code.AuthError }
941978
+ )
941715
941979
  });
941716
941980
  }
941717
941981
 
@@ -941766,7 +942030,10 @@ function isIntrospectionResult(data2) {
941766
942030
  }
941767
942031
  function extractIntrospectionData(data2) {
941768
942032
  if (!data2 || typeof data2 !== "object") {
941769
- throw new Error("Data does not contain valid GraphQL introspection result");
942033
+ throw new CliError({
942034
+ message: "Data does not contain valid GraphQL introspection result",
942035
+ code: CliError.Code.InternalError
942036
+ });
941770
942037
  }
941771
942038
  if ("__schema" in data2 && data2.__schema) {
941772
942039
  return data2;
@@ -941774,7 +942041,10 @@ function extractIntrospectionData(data2) {
941774
942041
  if ("data" in data2 && data2.data && typeof data2.data === "object" && "__schema" in data2.data) {
941775
942042
  return data2.data;
941776
942043
  }
941777
- throw new Error("Data does not contain valid GraphQL introspection result");
942044
+ throw new CliError({
942045
+ message: "Data does not contain valid GraphQL introspection result",
942046
+ code: CliError.Code.InternalError
942047
+ });
941778
942048
  }
941779
942049
  async function tryGraphQLIntrospection(url3, logger4) {
941780
942050
  try {
@@ -941901,7 +942171,7 @@ Attempt 2 (GET direct fetch): ${getResult.error}
941901
942171
  To update the schema from its defined origin, please ensure the origin either:
941902
942172
  1. Accepts GraphQL introspection queries via POST, or
941903
942173
  2. Returns introspection results directly via GET`;
941904
- throw new Error(errorMessage);
942174
+ throw new CliError({ message: errorMessage, code: CliError.Code.InternalError });
941905
942175
  }
941906
942176
  async function updateApiSpec({
941907
942177
  cliContext,
@@ -945135,7 +945405,7 @@ async function rerunFernCliAtVersion({
945135
945405
  if (throwOnError) {
945136
945406
  throw new RerunCliError({ version: version7, stdout, stderr });
945137
945407
  }
945138
- cliContext.failWithoutThrowing();
945408
+ cliContext.failWithoutThrowing(void 0, void 0, { code: CliError.Code.InternalError });
945139
945409
  }
945140
945410
  }
945141
945411
 
@@ -945279,7 +945549,9 @@ function validateVersionAhead({
945279
945549
  const versionAhead = isVersionAhead(targetVersion, currentVersion);
945280
945550
  if (!versionAhead) {
945281
945551
  cliContext.failAndThrow(
945282
- `Cannot upgrade because target version (${targetVersion}) is not ahead of existing version ${currentVersion}`
945552
+ `Cannot upgrade because target version (${targetVersion}) is not ahead of existing version ${currentVersion}`,
945553
+ void 0,
945554
+ { code: CliError.Code.VersionError }
945283
945555
  );
945284
945556
  }
945285
945557
  }
@@ -945334,7 +945606,9 @@ async function upgrade({
945334
945606
  }
945335
945607
  const fernDirectory2 = await getFernDirectory();
945336
945608
  if (fernDirectory2 == null) {
945337
- return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
945609
+ return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, void 0, {
945610
+ code: CliError.Code.ConfigError
945611
+ });
945338
945612
  }
945339
945613
  const projectConfig2 = await cliContext.runTask(
945340
945614
  (context3) => loadProjectConfig({ directory: fernDirectory2, context: context3 })
@@ -945368,7 +945642,9 @@ async function upgrade({
945368
945642
  if (cliContext.environment.packageVersion === resolvedTargetVersion || isLocalDev) {
945369
945643
  const fernDirectory2 = await getFernDirectory();
945370
945644
  if (fernDirectory2 == null) {
945371
- return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
945645
+ return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, void 0, {
945646
+ code: CliError.Code.ConfigError
945647
+ });
945372
945648
  }
945373
945649
  const projectConfig2 = await cliContext.runTask(
945374
945650
  (context3) => loadProjectConfig({ directory: fernDirectory2, context: context3 })
@@ -945410,7 +945686,9 @@ async function upgrade({
945410
945686
  });
945411
945687
  const fernDirectory = await getFernDirectory();
945412
945688
  if (fernDirectory == null) {
945413
- return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
945689
+ return cliContext.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, void 0, {
945690
+ code: CliError.Code.ConfigError
945691
+ });
945414
945692
  }
945415
945693
  const projectConfig = await cliContext.runTask(
945416
945694
  (context3) => loadProjectConfig({ directory: fernDirectory, context: context3 })
@@ -945449,7 +945727,9 @@ async function upgrade({
945449
945727
  const isVersionNotFound = errorOutput.includes("ETARGET") || errorOutput.includes("E404") || errorOutput.includes("404 Not Found") || errorOutput.includes("No matching version found") || errorOutput.includes("version not found");
945450
945728
  if (isVersionNotFound) {
945451
945729
  return cliContext.failAndThrow(
945452
- `Failed to upgrade to ${resolvedTargetVersion} because it does not exist. See https://www.npmjs.com/package/${cliContext.environment.packageName}?activeTab=versions.`
945730
+ `Failed to upgrade to ${resolvedTargetVersion} because it does not exist. See https://www.npmjs.com/package/${cliContext.environment.packageName}?activeTab=versions.`,
945731
+ void 0,
945732
+ { code: CliError.Code.ConfigError }
945453
945733
  );
945454
945734
  }
945455
945735
  }
@@ -945465,7 +945745,7 @@ async function validateDocsBrokenLinks({
945465
945745
  }) {
945466
945746
  const docsWorkspace = project.docsWorkspaces;
945467
945747
  if (docsWorkspace == null) {
945468
- cliContext.failAndThrow("No docs workspace found");
945748
+ cliContext.failAndThrow("No docs workspace found", void 0, { code: CliError.Code.ConfigError });
945469
945749
  return;
945470
945750
  }
945471
945751
  await cliContext.runTaskForWorkspace(docsWorkspace, async (context3) => {
@@ -945488,7 +945768,7 @@ async function validateDocsBrokenLinks({
945488
945768
  elapsedMillis
945489
945769
  });
945490
945770
  if (violations.length > 0 && errorOnBrokenLinks) {
945491
- context3.failAndThrow();
945771
+ context3.failAndThrow(void 0, void 0, { code: CliError.Code.ValidationError });
945492
945772
  }
945493
945773
  });
945494
945774
  }
@@ -945970,7 +946250,7 @@ async function validateWorkspaces({
945970
946250
  if (!apiYmlExists) {
945971
946251
  await cliContext.runTask(async (context3) => {
945972
946252
  context3.logger.error(`Missing file: ${ROOT_API_FILENAME}`);
945973
- return context3.failAndThrow();
946253
+ return context3.failAndThrow(void 0, void 0, { code: CliError.Code.ValidationError });
945974
946254
  });
945975
946255
  return;
945976
946256
  }
@@ -946011,7 +946291,7 @@ async function validateWorkspaces({
946011
946291
  );
946012
946292
  }
946013
946293
  if (hasErrors || hasAnyErrors) {
946014
- cliContext.failAndThrow();
946294
+ cliContext.failAndThrow(void 0, void 0, { code: CliError.Code.ValidationError });
946015
946295
  }
946016
946296
  }
946017
946297
 
@@ -946229,7 +946509,10 @@ async function translateText({
946229
946509
  cliContext.logger.error(
946230
946510
  "Authentication required. Please run 'fern login' or set the FERN_TOKEN environment variable."
946231
946511
  );
946232
- throw new Error("Authentication required for translation service");
946512
+ throw new CliError({
946513
+ message: "Authentication required for translation service",
946514
+ code: CliError.Code.AuthError
946515
+ });
946233
946516
  }
946234
946517
  const config5 = {
946235
946518
  maxRetries: retryConfig.maxRetries ?? DEFAULT_MAX_RETRIES3,
@@ -946266,7 +946549,7 @@ async function translateText({
946266
946549
  errorDetail = await response.text();
946267
946550
  }
946268
946551
  if (response.status === 403) {
946269
- throw new Error(`403: ${errorDetail}`);
946552
+ throw new CliError({ message: `403: ${errorDetail}`, code: CliError.Code.AuthError });
946270
946553
  }
946271
946554
  const error50 = new Error(`HTTP ${response.status}: ${errorDetail}`);
946272
946555
  if (!isRetriableError(error50, response)) {
@@ -946946,7 +947229,10 @@ async function writeTranslationForProject({
946946
947229
  const translationsDirectory = join8(fernDirectory, RelativeFilePath2.of("translations"));
946947
947230
  const sourceLanguage = languages[0];
946948
947231
  if (!sourceLanguage) {
946949
- throw new Error("Unexpected error - first element of languages array is invalid");
947232
+ throw new CliError({
947233
+ message: "Unexpected error - first element of languages array is invalid",
947234
+ code: CliError.Code.InternalError
947235
+ });
946950
947236
  }
946951
947237
  if (!(0, import_fs38.existsSync)(translationsDirectory)) {
946952
947238
  context3.logger.debug(`Creating translations directory at: ${translationsDirectory}`);
@@ -947259,19 +947545,23 @@ async function resolveGroupGithubConfig(cliContext, groupName, apiWorkspace) {
947259
947545
  });
947260
947546
  const workspace = project.apiWorkspaces[0];
947261
947547
  if (workspace == null) {
947262
- return cliContext.failAndThrow("No API workspace found.");
947548
+ return cliContext.failAndThrow("No API workspace found.", void 0, { code: CliError.Code.ConfigError });
947263
947549
  }
947264
947550
  const generatorsConfig = workspace.generatorsConfiguration;
947265
947551
  if (generatorsConfig == null) {
947266
- return cliContext.failAndThrow("No generators.yml found in workspace.");
947552
+ return cliContext.failAndThrow("No generators.yml found in workspace.", void 0, {
947553
+ code: CliError.Code.ConfigError
947554
+ });
947267
947555
  }
947268
947556
  const group = generatorsConfig.groups.find((g19) => g19.groupName === groupName);
947269
947557
  if (group == null) {
947270
947558
  const available = generatorsConfig.groups.map((g19) => g19.groupName).join(", ");
947271
- return cliContext.failAndThrow(`Group "${groupName}" not found. Available groups: ${available}`);
947559
+ return cliContext.failAndThrow(`Group "${groupName}" not found. Available groups: ${available}`, void 0, {
947560
+ code: CliError.Code.ConfigError
947561
+ });
947272
947562
  }
947273
947563
  const resolveEnv = (value) => replaceEnvVariables(value, {
947274
- onError: (message) => cliContext.failAndThrow(message)
947564
+ onError: (message) => cliContext.failAndThrow(message, void 0, { code: CliError.Code.ConfigError })
947275
947565
  });
947276
947566
  const generatorWithSelfhosted = group.generators.find(
947277
947567
  (g19) => g19.raw?.github != null && isGithubSelfhosted(g19.raw.github)
@@ -947302,7 +947592,9 @@ async function resolveGroupGithubConfig(cliContext, groupName, apiWorkspace) {
947302
947592
  branch: "branch" in githubConfig ? githubConfig.branch : void 0
947303
947593
  };
947304
947594
  }
947305
- return cliContext.failAndThrow(`No generator in group "${groupName}" has a github configuration.`);
947595
+ return cliContext.failAndThrow(`No generator in group "${groupName}" has a github configuration.`, void 0, {
947596
+ code: CliError.Code.ConfigError
947597
+ });
947306
947598
  }
947307
947599
 
947308
947600
  // src/runtime.ts
@@ -947432,7 +947724,7 @@ async function tryRunCli(cliContext) {
947432
947724
  cliContext.logger.info(cliContext.environment.packageVersion);
947433
947725
  } else {
947434
947726
  cli.showHelp();
947435
- cliContext.failAndThrow();
947727
+ cliContext.failAndThrow(void 0, void 0, { code: CliError.Code.ConfigError });
947436
947728
  }
947437
947729
  }
947438
947730
  ).option("log-level", {
@@ -947558,14 +947850,22 @@ function addInitCommand2(cli, cliContext) {
947558
947850
  }
947559
947851
  }
947560
947852
  if (argv.api != null && argv.docs != null) {
947561
- return cliContext.failWithoutThrowing("Cannot specify both --api and --docs. Please choose one.");
947853
+ return cliContext.failWithoutThrowing(
947854
+ "Cannot specify both --api and --docs. Please choose one.",
947855
+ void 0,
947856
+ { code: CliError.Code.ConfigError }
947857
+ );
947562
947858
  } else if (argv.readme != null && argv.mintlify != null) {
947563
947859
  return cliContext.failWithoutThrowing(
947564
- "Cannot specify both --readme and --mintlify. Please choose one."
947860
+ "Cannot specify both --readme and --mintlify. Please choose one.",
947861
+ void 0,
947862
+ { code: CliError.Code.ConfigError }
947565
947863
  );
947566
947864
  } else if (argv.openapi != null && argv["fern-definition"] === true) {
947567
947865
  return cliContext.failWithoutThrowing(
947568
- "Cannot specify both --openapi and --fern-definition. Please choose one."
947866
+ "Cannot specify both --openapi and --fern-definition. Please choose one.",
947867
+ void 0,
947868
+ { code: CliError.Code.ConfigError }
947569
947869
  );
947570
947870
  } else if (argv.readme != null) {
947571
947871
  await cliContext.runTask(async (context3) => {
@@ -947599,7 +947899,9 @@ function addInitCommand2(cli, cliContext) {
947599
947899
  if (isURL(argv.openapi)) {
947600
947900
  const result = await loadOpenAPIFromUrl({ url: argv.openapi, logger: cliContext.logger });
947601
947901
  if (result.status === LoadOpenAPIStatus.Failure) {
947602
- cliContext.failAndThrow(result.errorMessage);
947902
+ cliContext.failAndThrow(result.errorMessage, void 0, {
947903
+ code: CliError.Code.NetworkError
947904
+ });
947603
947905
  }
947604
947906
  const tmpFilepath = result.filePath;
947605
947907
  absoluteOpenApiPath = AbsoluteFilePath2.of(tmpFilepath);
@@ -947608,7 +947910,9 @@ function addInitCommand2(cli, cliContext) {
947608
947910
  }
947609
947911
  const pathExists2 = await doesPathExist(absoluteOpenApiPath);
947610
947912
  if (!pathExists2) {
947611
- cliContext.failAndThrow(`${absoluteOpenApiPath} does not exist`);
947913
+ cliContext.failAndThrow(`${absoluteOpenApiPath} does not exist`, void 0, {
947914
+ code: CliError.Code.ConfigError
947915
+ });
947612
947916
  }
947613
947917
  }
947614
947918
  await cliContext.runTask(async (context3) => {
@@ -947652,9 +947956,10 @@ function addDiffCommand(cli, cliContext) {
947652
947956
  description: "Whether to suppress output written to stderr"
947653
947957
  }).middleware((argv) => {
947654
947958
  if (!haveSameNullishness(argv.fromGeneratorVersion, argv.toGeneratorVersion)) {
947655
- throw new Error(
947656
- "Both --from-generator-version and --to-generator-version must be provided together, or neither should be provided"
947657
- );
947959
+ throw new CliError({
947960
+ message: "Both --from-generator-version and --to-generator-version must be provided together, or neither should be provided",
947961
+ code: CliError.Code.ValidationError
947962
+ });
947658
947963
  }
947659
947964
  }),
947660
947965
  async (argv) => {
@@ -947905,50 +948210,84 @@ function addGenerateCommand2(cli, cliContext) {
947905
948210
  }),
947906
948211
  async (argv) => {
947907
948212
  if (argv.api != null && argv.docs != null) {
947908
- return cliContext.failWithoutThrowing("Cannot specify both --api and --docs. Please choose one.");
948213
+ return cliContext.failWithoutThrowing(
948214
+ "Cannot specify both --api and --docs. Please choose one.",
948215
+ void 0,
948216
+ { code: CliError.Code.ConfigError }
948217
+ );
947909
948218
  }
947910
948219
  if (argv.id != null && !argv.preview) {
947911
- return cliContext.failWithoutThrowing("The --id flag can only be used with --preview.");
948220
+ return cliContext.failWithoutThrowing("The --id flag can only be used with --preview.", void 0, {
948221
+ code: CliError.Code.ConfigError
948222
+ });
947912
948223
  }
947913
948224
  if (argv.id != null && argv.docs == null) {
947914
- return cliContext.failWithoutThrowing("The --id flag can only be used with --docs.");
948225
+ return cliContext.failWithoutThrowing("The --id flag can only be used with --docs.", void 0, {
948226
+ code: CliError.Code.ConfigError
948227
+ });
947915
948228
  }
947916
948229
  if (argv.skipUpload && !argv.preview) {
947917
- return cliContext.failWithoutThrowing("The --skip-upload flag can only be used with --preview.");
948230
+ return cliContext.failWithoutThrowing(
948231
+ "The --skip-upload flag can only be used with --preview.",
948232
+ void 0,
948233
+ { code: CliError.Code.ConfigError }
948234
+ );
947918
948235
  }
947919
948236
  if (argv.skipUpload && argv.docs == null) {
947920
- return cliContext.failWithoutThrowing("The --skip-upload flag can only be used with --docs.");
948237
+ return cliContext.failWithoutThrowing(
948238
+ "The --skip-upload flag can only be used with --docs.",
948239
+ void 0,
948240
+ { code: CliError.Code.ConfigError }
948241
+ );
947921
948242
  }
947922
948243
  if (argv.fernignore != null && (argv.local || argv.runner != null)) {
947923
948244
  return cliContext.failWithoutThrowing(
947924
- "The --fernignore flag is not supported with local generation (--local or --runner). It can only be used with remote generation."
948245
+ "The --fernignore flag is not supported with local generation (--local or --runner). It can only be used with remote generation.",
948246
+ void 0,
948247
+ { code: CliError.Code.ConfigError }
947925
948248
  );
947926
948249
  }
947927
948250
  if (argv["skip-fernignore"] && argv.fernignore != null) {
947928
948251
  return cliContext.failWithoutThrowing(
947929
- "The --skip-fernignore and --fernignore flags cannot be used together."
948252
+ "The --skip-fernignore and --fernignore flags cannot be used together.",
948253
+ void 0,
948254
+ { code: CliError.Code.ConfigError }
947930
948255
  );
947931
948256
  }
947932
948257
  if (argv["dynamic-ir-only"] && (argv.local || argv.runner != null)) {
947933
948258
  return cliContext.failWithoutThrowing(
947934
- "The --dynamic-ir-only flag is not supported with local generation (--local or --runner). It can only be used with remote generation."
948259
+ "The --dynamic-ir-only flag is not supported with local generation (--local or --runner). It can only be used with remote generation.",
948260
+ void 0,
948261
+ { code: CliError.Code.ConfigError }
947935
948262
  );
947936
948263
  }
947937
948264
  if (argv["dynamic-ir-only"] && argv.version == null) {
947938
948265
  return cliContext.failWithoutThrowing(
947939
- "The --dynamic-ir-only flag requires a version to be specified with --version."
948266
+ "The --dynamic-ir-only flag requires a version to be specified with --version.",
948267
+ void 0,
948268
+ { code: CliError.Code.ConfigError }
947940
948269
  );
947941
948270
  }
947942
948271
  if (argv["dynamic-ir-only"] && argv.docs != null) {
947943
948272
  return cliContext.failWithoutThrowing(
947944
- "The --dynamic-ir-only flag can only be used for API generation, not docs generation."
948273
+ "The --dynamic-ir-only flag can only be used for API generation, not docs generation.",
948274
+ void 0,
948275
+ { code: CliError.Code.ConfigError }
947945
948276
  );
947946
948277
  }
947947
948278
  if (argv.output != null && !argv.preview) {
947948
- return cliContext.failWithoutThrowing("The --output flag currently only works with --preview.");
948279
+ return cliContext.failWithoutThrowing(
948280
+ "The --output flag currently only works with --preview.",
948281
+ void 0,
948282
+ { code: CliError.Code.ConfigError }
948283
+ );
947949
948284
  }
947950
948285
  if (argv.output != null && argv.docs != null) {
947951
- return cliContext.failWithoutThrowing("The --output flag is not supported for docs generation.");
948286
+ return cliContext.failWithoutThrowing(
948287
+ "The --output flag is not supported for docs generation.",
948288
+ void 0,
948289
+ { code: CliError.Code.ConfigError }
948290
+ );
947952
948291
  }
947953
948292
  const correctedGeneratorFilter = argv.generator != null ? warnAndCorrectIncorrectDockerOrg(argv.generator, cliContext) : void 0;
947954
948293
  const { generatorName, generatorIndex } = parseGeneratorArg(correctedGeneratorFilter);
@@ -948880,17 +949219,26 @@ function addDocsDevCommand(cli, cliContext) {
948880
949219
  );
948881
949220
  }
948882
949221
  let port;
948883
- if (argv.port != null) {
948884
- port = argv.port;
948885
- } else {
948886
- port = await getPorts({ port: [3e3, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010] });
948887
- }
948888
949222
  let backendPort;
948889
- if (argv.backendPort != null) {
948890
- backendPort = argv.backendPort;
948891
- } else {
948892
- backendPort = await getPorts({
948893
- port: [3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011]
949223
+ try {
949224
+ if (argv.port != null) {
949225
+ port = argv.port;
949226
+ } else {
949227
+ port = await getPorts({
949228
+ port: [3e3, 3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010]
949229
+ });
949230
+ }
949231
+ if (argv.backendPort != null) {
949232
+ backendPort = argv.backendPort;
949233
+ } else {
949234
+ backendPort = await getPorts({
949235
+ port: [3001, 3002, 3003, 3004, 3005, 3006, 3007, 3008, 3009, 3010, 3011]
949236
+ });
949237
+ }
949238
+ } catch (error50) {
949239
+ throw new CliError({
949240
+ message: `Failed to find an available port: ${error50 instanceof Error ? error50.message : String(error50)}`,
949241
+ code: CliError.Code.EnvironmentError
948894
949242
  });
948895
949243
  }
948896
949244
  const bundlePath = argv.bundlePath;
@@ -948943,7 +949291,7 @@ function addDocsMdCheckCommand(cli, cliContext) {
948943
949291
  defaultToAllApiWorkspaces: true
948944
949292
  });
948945
949293
  if (project.docsWorkspaces == null) {
948946
- cliContext.failAndThrow("No docs workspace found");
949294
+ cliContext.failAndThrow("No docs workspace found", void 0, { code: CliError.Code.ConfigError });
948947
949295
  }
948948
949296
  const docsWorkspace = project.docsWorkspaces;
948949
949297
  let hasErrors = false;
@@ -948958,7 +949306,7 @@ function addDocsMdCheckCommand(cli, cliContext) {
948958
949306
  }
948959
949307
  });
948960
949308
  if (hasErrors) {
948961
- cliContext.failWithoutThrowing();
949309
+ cliContext.failWithoutThrowing(void 0, void 0, { code: CliError.Code.ValidationError });
948962
949310
  }
948963
949311
  }
948964
949312
  );
@@ -949317,7 +949665,7 @@ function addBetaCommand(cli, cliContext) {
949317
949665
  await runCliV2(v2Args);
949318
949666
  } catch (error50) {
949319
949667
  cliContext.logger.error("CLI v2 failed:", String(error50));
949320
- cliContext.failWithoutThrowing();
949668
+ cliContext.failWithoutThrowing(void 0, error50, { code: CliError.Code.InternalError });
949321
949669
  }
949322
949670
  }
949323
949671
  );
@@ -949442,7 +949790,11 @@ function addReplayInitCommand(cli, cliContext) {
949442
949790
  }
949443
949791
  if (githubRepo == null) {
949444
949792
  return cliContext.failAndThrow(
949445
- "Missing required github config. Either use --group to read from generators.yml, or provide --github directly."
949793
+ "Missing required github config. Either use --group to read from generators.yml, or provide --github directly.",
949794
+ void 0,
949795
+ {
949796
+ code: CliError.Code.ConfigError
949797
+ }
949446
949798
  );
949447
949799
  }
949448
949800
  if (token == null) {
@@ -949478,7 +949830,9 @@ function addReplayInitCommand(cli, cliContext) {
949478
949830
  return;
949479
949831
  }
949480
949832
  if (result.lockfileContent == null) {
949481
- return cliContext.failAndThrow("Bootstrap succeeded but lockfile content is missing.");
949833
+ return cliContext.failAndThrow("Bootstrap succeeded but lockfile content is missing.", void 0, {
949834
+ code: CliError.Code.InternalError
949835
+ });
949482
949836
  }
949483
949837
  const fernToken = await cliContext.runTask((context3) => askToLogin(context3));
949484
949838
  const { owner, repo } = parseOwnerRepo(githubRepo);
@@ -949500,18 +949854,24 @@ function addReplayInitCommand(cli, cliContext) {
949500
949854
  if (!response.ok) {
949501
949855
  if (response.status === 404) {
949502
949856
  return cliContext.failAndThrow(
949503
- "The Fern GitHub App is not installed on this repository. Install it at https://github.com/apps/fern-api to enable server-side PR creation."
949857
+ "The Fern GitHub App is not installed on this repository. Install it at https://github.com/apps/fern-api to enable server-side PR creation.",
949858
+ void 0,
949859
+ { code: CliError.Code.ConfigError }
949504
949860
  );
949505
949861
  }
949506
949862
  const body = await response.text();
949507
- return cliContext.failAndThrow(`Failed to create PR via Fern: ${body}`);
949863
+ return cliContext.failAndThrow(`Failed to create PR via Fern: ${body}`, void 0, {
949864
+ code: CliError.Code.NetworkError
949865
+ });
949508
949866
  }
949509
949867
  const data2 = await response.json();
949510
949868
  cliContext.logger.info(`
949511
949869
  PR created: ${data2.prUrl}`);
949512
949870
  cliContext.logger.info("Merge the PR to enable Replay for this repository.");
949513
949871
  } catch (error50) {
949514
- cliContext.failAndThrow(`Failed to initialize Replay: ${extractErrorMessage(error50)}`);
949872
+ cliContext.failAndThrow(`Failed to initialize Replay: ${extractErrorMessage(error50)}`, error50, {
949873
+ code: CliError.Code.NetworkError
949874
+ });
949515
949875
  }
949516
949876
  }
949517
949877
  );
@@ -949574,12 +949934,18 @@ Resolve the conflicts in your editor, then run \`fern replay resolve\` again to
949574
949934
  }
949575
949935
  cliContext.logger.warn(`Resolve them first, then run \`fern replay resolve\` again.`);
949576
949936
  } else {
949577
- cliContext.failAndThrow(`Resolve failed: ${result.reason ?? "unknown error"}`);
949937
+ cliContext.failAndThrow(
949938
+ `Resolve failed: ${result.reason ?? "unknown error"}`,
949939
+ void 0,
949940
+ { code: CliError.Code.InternalError }
949941
+ );
949578
949942
  }
949579
949943
  }
949580
949944
  }
949581
949945
  } catch (error50) {
949582
- cliContext.failAndThrow(`Failed to resolve: ${extractErrorMessage(error50)}`);
949946
+ cliContext.failAndThrow(`Failed to resolve: ${extractErrorMessage(error50)}`, error50, {
949947
+ code: CliError.Code.InternalError
949948
+ });
949583
949949
  }
949584
949950
  }
949585
949951
  );
@@ -949795,7 +950161,10 @@ function parseOwnerRepo(githubRepo) {
949795
950161
  const owner = parts[parts.length - 2];
949796
950162
  const repo = parts[parts.length - 1];
949797
950163
  if (owner == null || repo == null) {
949798
- throw new Error(`Could not parse owner/repo from: ${githubRepo}`);
950164
+ throw new CliError({
950165
+ message: `Could not parse owner/repo from: ${githubRepo}`,
950166
+ code: CliError.Code.ParseError
950167
+ });
949799
950168
  }
949800
950169
  return { owner, repo };
949801
950170
  }