Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(improvement, fern): Add better error for invalid generators.yml #3521

Merged
merged 3 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AbsoluteFilePath, doesPathExist, join, RelativeFilePath } from "@fern-a
import { TaskContext } from "@fern-api/task-context";
import { readFile } from "fs/promises";
import yaml from "js-yaml";
import path from "path";
import { validateSchema } from "../commons/validateSchema";
import { GENERATORS_CONFIGURATION_FILENAME } from "../constants";
import { convertGeneratorsConfiguration } from "./convertGeneratorsConfiguration";
Expand All @@ -20,13 +21,22 @@ export async function loadRawGeneratorsConfiguration({
return undefined;
}
const contentsStr = await readFile(filepath);
const contentsParsed = yaml.load(contentsStr.toString());
return validateSchema({
schema: GeneratorsConfigurationSchema,
value: contentsParsed,
context,
filepathBeingParsed: filepath
});
try {
const contentsParsed = yaml.load(contentsStr.toString());
return validateSchema({
schema: GeneratorsConfigurationSchema,
value: contentsParsed,
context,
filepathBeingParsed: filepath
});
} catch (e) {
if (e instanceof yaml.YAMLException) {
context.failAndThrow(`Failed to parse ${path.relative(process.cwd(), filepath)}: ${e.reason}`);
} else {
throw e;
}
}
return undefined;
}

export async function loadGeneratorsConfiguration({
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/workspace-loader/src/loadAPIWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ export async function loadAPIWorkspace({
cliVersion: string;
workspaceName: string | undefined;
}): Promise<WorkspaceLoader.Result> {
let generatorsConfiguration: generatorsYml.GeneratorsConfiguration | undefined = undefined;
try {
generatorsConfiguration = await generatorsYml.loadGeneratorsConfiguration({ absolutePathToWorkspace, context });
} catch (err) {}
const generatorsConfiguration = await generatorsYml.loadGeneratorsConfiguration({
absolutePathToWorkspace,
context
});

let changelog: APIChangelog | undefined = undefined;
try {
Expand Down