Skip to content

Commit c82a0cd

Browse files
committed
refactor(cli): remove LoggableFernCliError in favor of CliError
Replace all LoggableFernCliError throw sites with CliError.internalError() and remove the dedicated catch branches since CliError is already handled upstream. Deletes the now-unused LoggableFernCliError class. Made-with: Cursor
1 parent ffd9aee commit c82a0cd

File tree

6 files changed

+6
-19
lines changed

6 files changed

+6
-19
lines changed

packages/cli/cli/src/cli.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
import { LOG_LEVELS, LogLevel } from "@fern-api/logger";
3434
import { askToLogin, login, logout } from "@fern-api/login";
3535
import { protocGenFern } from "@fern-api/protoc-gen-fern";
36-
import { CliError, LoggableFernCliError, TaskAbortSignal } from "@fern-api/task-context";
36+
import { CliError, TaskAbortSignal } from "@fern-api/task-context";
3737
import getPort from "get-port";
3838
import { Argv } from "yargs";
3939
import { hideBin } from "yargs/helpers";
@@ -145,8 +145,6 @@ async function runCli() {
145145
cliContext.failWithoutThrowing(undefined, error, { code: "ENVIRONMENT_ERROR" });
146146
} else if (error instanceof TaskAbortSignal) {
147147
cliContext.failWithoutThrowing();
148-
} else if (error instanceof LoggableFernCliError) {
149-
cliContext.logger.error(`Failed. ${error.log}`);
150148
} else {
151149
cliContext.failWithoutThrowing("Failed.", error, { code: "INTERNAL_ERROR" });
152150
}

packages/cli/generation/ir-generator/src/extended-properties/addExtendedPropertiesToIr.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ObjectTypeDeclaration,
77
TypeDeclaration
88
} from "@fern-api/ir-sdk";
9-
import { LoggableFernCliError } from "@fern-api/task-context";
9+
import { CliError } from "@fern-api/task-context";
1010

1111
import { getTypeDeclaration } from "../utils/getTypeDeclaration.js";
1212

@@ -96,9 +96,7 @@ function getObjectTypeDeclarationFromTypeId(typeId: string, ir: TypesAndServices
9696
}
9797
}
9898

99-
throw new LoggableFernCliError(
100-
`Unexpected error: ${typeId} is extended but has shape ${typeDeclaration.shape.type}`
101-
);
99+
throw CliError.internalError(`Unexpected error: ${typeId} is extended but has shape ${typeDeclaration.shape.type}`);
102100
}
103101

104102
function getAllPropertiesForObject({
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { TypeDeclaration } from "@fern-api/ir-sdk";
2-
import { LoggableFernCliError } from "@fern-api/task-context";
2+
import { CliError } from "@fern-api/task-context";
33

44
export function getTypeDeclaration(typeId: string, types: Record<string, TypeDeclaration>): TypeDeclaration {
55
const maybeTypeDeclaration = types[typeId];
66
if (maybeTypeDeclaration == null) {
7-
throw new LoggableFernCliError(`Illegal Error: Failed to load type declaration for type ${typeId}`);
7+
throw CliError.internalError(`Failed to load type declaration for type ${typeId}`);
88
}
99
return maybeTypeDeclaration;
1010
}

packages/cli/generation/local-generation/local-workspace-runner/src/GenerationRunner.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { generatorsYml, SNIPPET_JSON_FILENAME } from "@fern-api/configuration";
44
import { AbsoluteFilePath, join, RelativeFilePath } from "@fern-api/fs-utils";
55
import { generateIntermediateRepresentation } from "@fern-api/ir-generator";
66
import { IntermediateRepresentation } from "@fern-api/ir-sdk";
7-
import { LoggableFernCliError, TaskAbortSignal, TaskContext } from "@fern-api/task-context";
7+
import { TaskAbortSignal, TaskContext } from "@fern-api/task-context";
88
import { FernGeneratorExec } from "@fern-fern/generator-exec-sdk";
99
import chalk from "chalk";
1010
import { generateDynamicSnippetTests } from "./dynamic-snippets/generateDynamicSnippetTests.js";
@@ -101,8 +101,6 @@ export class GenerationRunner {
101101
} catch (error) {
102102
if (error instanceof TaskAbortSignal) {
103103
// already logged by failAndThrow, nothing to do
104-
} else if (error instanceof LoggableFernCliError) {
105-
interactiveTaskContext.failWithoutThrowing(`Generation failed: ${error.log}`, error);
106104
} else {
107105
interactiveTaskContext.failWithoutThrowing(
108106
`Generation failed: ${error instanceof Error ? error.message : "Unknown error"}`,

packages/cli/task-context/src/LoggableFernCliError.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/cli/task-context/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export { CliError, resolveErrorCode, shouldReportToSentry } from "./CliError.js";
2-
export { LoggableFernCliError } from "./LoggableFernCliError.js";
32
export { createMockTaskContext } from "./MockTaskContext.js";
43
export { TaskAbortSignal } from "./TaskAbortSignal.js";
54
export {

0 commit comments

Comments
 (0)