Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllYamlFiles(context: TaskContext): Promise<AbsoluteFil
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/definition/**/*.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { CliError } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";

import { Migration } from "../../../types/Migration.js";
Expand All @@ -15,7 +16,7 @@ export const migration: Migration = {
const newContents = addDiscriminantToFile(fileContents);
await writeFile(yamlFilepath, newContents);
} catch (error) {
context.failAndThrow("Failed to migrate " + yamlFilepath, error);
context.failAndThrow("Failed to migrate " + yamlFilepath, error, { code: CliError.Code.ParseError });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllYamlFiles(context: TaskContext): Promise<AbsoluteFil
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/definition/**/*.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";
import YAML from "yaml";

Expand All @@ -15,7 +15,9 @@ export const migration: Migration = {
try {
await migrateFile(filepath, context);
} catch (error) {
context.failWithoutThrowing(`Failed to add 'key' property to union in ${filepath}`, error);
context.failWithoutThrowing(`Failed to add 'key' property to union in ${filepath}`, error, {
code: CliError.Code.ParseError
});
}
}
}
Expand All @@ -29,7 +31,9 @@ async function migrateFile(filepath: AbsoluteFilePath, context: TaskContext): Pr
return;
}
if (!YAML.isMap(types)) {
context.failWithoutThrowing(`"types" is not a map in ${filepath}`);
context.failWithoutThrowing(`"types" is not a map in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}

Expand All @@ -40,7 +44,9 @@ async function migrateFile(filepath: AbsoluteFilePath, context: TaskContext): Pr
continue;
}
if (!YAML.isMap(union)) {
context.failWithoutThrowing(`"union" is not a map in ${filepath}`);
context.failWithoutThrowing(`"union" is not a map in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
continue;
}
for (const singleUnionType of union.items) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllGeneratorYamlFiles(context: TaskContext): Promise<Ab
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/generators.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";
import YAML from "yaml";

Expand All @@ -15,7 +15,7 @@ export const migration: Migration = {
try {
await migrateGeneratorsYml(filepath, context);
} catch (error) {
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error);
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error, { code: CliError.Code.ParseError });
}
}
}
Expand All @@ -29,17 +29,23 @@ async function migrateGeneratorsYml(filepath: AbsoluteFilePath, context: TaskCon
return;
}
if (!YAML.isSeq(draftGenerators)) {
context.failWithoutThrowing(`draft generators are not a list in ${filepath}`);
context.failWithoutThrowing(`draft generators are not a list in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}
draftGenerators.items.forEach((draftGenerator) => {
if (!YAML.isMap(draftGenerator)) {
context.failWithoutThrowing(`draft generator is not an object in ${filepath}`);
context.failWithoutThrowing(`draft generator is not an object in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}
const name = draftGenerator.get("name", true);
if (typeof name?.value !== "string") {
context.failWithoutThrowing(`draft generator didn't have name in ${filepath}`);
context.failWithoutThrowing(`draft generator didn't have name in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}
const localOutput = draftGenerator.get("local-output");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllYamlFiles(context: TaskContext): Promise<AbsoluteFil
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/definition/**/*.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";
import YAML from "yaml";

Expand All @@ -15,7 +15,9 @@ export const migration: Migration = {
try {
await migrateFile(filepath, context);
} catch (error) {
context.failWithoutThrowing(`Failed to add 'key' property to union in ${filepath}`, error);
context.failWithoutThrowing(`Failed to add 'key' property to union in ${filepath}`, error, {
code: CliError.Code.ParseError
});
}
}
}
Expand All @@ -32,7 +34,9 @@ async function migrateFile(filepath: AbsoluteFilePath, context: TaskContext): Pr
[typeName]: typeDeclaration
});
} else if (!YAML.isMap(types)) {
context.failWithoutThrowing(`"types" is not a map in ${filepath}`);
context.failWithoutThrowing(`"types" is not a map in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
} else {
types.set(typeName, typeDeclaration);
}
Expand All @@ -44,13 +48,17 @@ async function migrateFile(filepath: AbsoluteFilePath, context: TaskContext): Pr
}

if (!YAML.isMap(errors)) {
context.failWithoutThrowing(`"errors" is not a map in ${filepath}`);
context.failWithoutThrowing(`"errors" is not a map in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}

for (const errorDeclaration of errors.items) {
if (!YAML.isMap(errorDeclaration.value)) {
context.failWithoutThrowing(`Error "${errorDeclaration.key}" is not a map in ${filepath}`);
context.failWithoutThrowing(`Error "${errorDeclaration.key}" is not a map in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
continue;
}

Expand All @@ -66,7 +74,11 @@ async function migrateFile(filepath: AbsoluteFilePath, context: TaskContext): Pr
const httpSection = errorDeclaration.value.get("http");
if (httpSection != null) {
if (!YAML.isMap(httpSection)) {
context.failWithoutThrowing(`http in "${errorDeclaration.key}" is not a map in ${filepath}`);
context.failWithoutThrowing(
`http in "${errorDeclaration.key}" is not a map in ${filepath}`,
undefined,
{ code: CliError.Code.ParseError }
);
} else {
const statusCode = httpSection.get("statusCode", true);
errorDeclaration.value.delete("http");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllGeneratorYamlFiles(context: TaskContext): Promise<Ab
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/generators.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";
import YAML from "yaml";

Expand All @@ -15,7 +15,7 @@ export const migration: Migration = {
try {
await migrateGeneratorsYml(filepath, context);
} catch (error) {
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error);
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error, { code: CliError.Code.ParseError });
}
}
}
Expand All @@ -29,17 +29,23 @@ async function migrateGeneratorsYml(filepath: AbsoluteFilePath, context: TaskCon
return;
}
if (!YAML.isSeq(releaseGenerators)) {
context.failWithoutThrowing(`release generators are not a list in ${filepath}`);
context.failWithoutThrowing(`release generators are not a list in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}
releaseGenerators.items.forEach((releaseGenerator) => {
if (!YAML.isMap(releaseGenerator)) {
context.failWithoutThrowing(`release generator is not an object in ${filepath}`);
context.failWithoutThrowing(`release generator is not an object in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}
const outputs = releaseGenerator.get("outputs");
if (!YAML.isMap(outputs)) {
context.failWithoutThrowing(`outputs is not an object in ${filepath}`);
context.failWithoutThrowing(`outputs is not an object in ${filepath}`, undefined, {
code: CliError.Code.ParseError
});
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllYamlFiles(context: TaskContext): Promise<AbsoluteFil
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/definition/**/*.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllRootApiYamlFiles(context: TaskContext): Promise<Abso
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/definition/api.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllGeneratorYamlFiles(context: TaskContext): Promise<Ab
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/generators.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertNever } from "@fern-api/core-utils";
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { CliError } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";
import yaml from "js-yaml";

Expand All @@ -17,7 +18,7 @@ export const migration: Migration = {
try {
await migrateGeneratorsYml(filepath);
} catch (error) {
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error);
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error, { code: CliError.Code.ParseError });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { TaskContext } from "@fern-api/task-context";
import { CliError, TaskContext } from "@fern-api/task-context";
import { findUp } from "find-up";
import { glob } from "glob";

Expand All @@ -9,7 +9,9 @@ export async function getAllRootApiYamlFiles(context: TaskContext): Promise<Abso
const fernDirectory = await getFernDirectory();
const alphasort = (a: string, b: string) => a.localeCompare(b, "en");
if (fernDirectory == null) {
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`);
return context.failAndThrow(`Directory "${FERN_DIRECTORY}" not found.`, undefined, {
code: CliError.Code.ConfigError
});
}
const filepaths = await glob("*/definition/api.yml", {
cwd: fernDirectory,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { CliError } from "@fern-api/task-context";
import { readFile, writeFile } from "fs/promises";
import YAML from "yaml";

Expand All @@ -14,7 +15,7 @@ export const migration: Migration = {
try {
await migrateRootApiFile(filepath);
} catch (error) {
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error);
context.failWithoutThrowing(`Failed to migrate ${filepath}`, error, { code: CliError.Code.ParseError });
}
}
}
Expand Down
Loading
Loading