Skip to content

Commit

Permalink
fixup! feat(cli): build based on configuration
Browse files Browse the repository at this point in the history
use string instead of any
  • Loading branch information
endersonmaia committed Oct 15, 2024
1 parent 82c68f9 commit 381f9bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
32 changes: 16 additions & 16 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,49 @@ import { TomlPrimitive, parse as parseToml } from "smol-toml";
* Typed Errors
*/
export class InvalidBuilderError extends Error {
constructor(builder: any) {
constructor(builder: string) {
super(`Invalid builder: ${builder}`);
this.name = "InvalidBuilder";
}
}

export class InvalidDriveFormatError extends Error {
constructor(format: any) {
constructor(format: string) {
super(`Invalid drive format: ${format}`);
this.name = "InvalidDriveFormatError";
}
}

export class InvalidEmptyDriveFormatError extends Error {
constructor(format: any) {
constructor(format: string) {
super(`Invalid empty drive format: ${format}`);
this.name = "InvalidEmptyDriveFormatError";
}
}

export class InvalidStringValueError extends Error {
constructor(value: any) {
constructor(value: string) {
super(`Invalid string value: ${value}`);
this.name = "InvalidStringValueError";
}
}

export class InvalidBooleanValueError extends Error {
constructor(value: any) {
constructor(value: string) {
super(`Invalid boolean value: ${value}`);
this.name = "InvalidBooleanValueError";
}
}

export class InvalidNumberValueError extends Error {
constructor(value: any) {
constructor(value: string) {
super(`Invalid number value: ${value}`);
this.name = "InvalidNumberValueError";
}
}

export class InvalidBytesValueError extends Error {
constructor(value: any) {
constructor(value: string) {
super(`Invalid bytes value: ${value}`);
this.name = "InvalidBytesValueError";
}
Expand Down Expand Up @@ -207,7 +207,7 @@ const parseBoolean = (value: TomlPrimitive, defaultValue: boolean): boolean => {
} else if (typeof value === "boolean") {
return value;
}
throw new InvalidBooleanValueError(value);
throw new InvalidBooleanValueError(value as string);
};

const parseOptionalBoolean = (value: TomlPrimitive): boolean | undefined => {
Expand All @@ -216,7 +216,7 @@ const parseOptionalBoolean = (value: TomlPrimitive): boolean | undefined => {
} else if (typeof value === "boolean") {
return value;
}
throw new InvalidBooleanValueError(value);
throw new InvalidBooleanValueError(value as string);
};

const parseString = (value: TomlPrimitive, defaultValue: string): string => {
Expand All @@ -225,7 +225,7 @@ const parseString = (value: TomlPrimitive, defaultValue: string): string => {
} else if (typeof value === "string") {
return value;
}
throw new InvalidStringValueError(value);
throw new InvalidStringValueError(value as unknown as string);
};

const parseStringArray = (value: TomlPrimitive): string[] => {
Expand All @@ -238,7 +238,7 @@ const parseStringArray = (value: TomlPrimitive): string[] => {
if (typeof v === "string") {
return v;
}
throw new InvalidStringValueError(v);
throw new InvalidStringValueError(v as unknown as string);
});
}
throw new InvalidStringArrayError();
Expand All @@ -250,7 +250,7 @@ const parseRequiredString = (value: TomlPrimitive, key: string): string => {
} else if (typeof value === "string") {
return value;
}
throw new InvalidStringValueError(value);
throw new InvalidStringValueError(value as unknown as string);
};

const parseOptionalString = (value: TomlPrimitive): string | undefined => {
Expand All @@ -259,7 +259,7 @@ const parseOptionalString = (value: TomlPrimitive): string | undefined => {
} else if (typeof value === "string") {
return value;
}
throw new InvalidStringValueError(value);
throw new InvalidStringValueError(value as unknown as string);
};

const parseOptionalStringBoolean = (
Expand All @@ -272,7 +272,7 @@ const parseOptionalStringBoolean = (
} else if (typeof value === "boolean") {
return value;
}
throw new InvalidStringValueError(value);
throw new InvalidStringValueError(value as unknown as string);
};

const parseOptionalNumber = (value: TomlPrimitive): bigint | undefined => {
Expand All @@ -283,7 +283,7 @@ const parseOptionalNumber = (value: TomlPrimitive): bigint | undefined => {
} else if (typeof value === "number") {
return BigInt(value);
}
throw new InvalidNumberValueError(value);
throw new InvalidNumberValueError(value as string);
};

const parseBytes = (value: TomlPrimitive, defaultValue: number): number => {
Expand All @@ -294,7 +294,7 @@ const parseBytes = (value: TomlPrimitive, defaultValue: number): number => {
} else if (typeof value === "number" || typeof value === "string") {
return bytes.parse(value);
}
throw new InvalidBytesValueError(value);
throw new InvalidBytesValueError(value as unknown as string);
};

const parseBuilder = (value: TomlPrimitive): Builder => {
Expand Down
24 changes: 13 additions & 11 deletions apps/cli/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ shared = true`);
new InvalidBuilderError("invalid"),
);
expect(() => parse("[drives.root]\nbuilder = true")).toThrowError(
new InvalidBuilderError(true),
new InvalidBuilderError(true as unknown as string),
);
expect(() => parse("[drives.root]\nbuilder = 10")).toThrowError(
new InvalidBuilderError(10),
new InvalidBuilderError(10 as unknown as string),
);
expect(() => parse("[drives.root]\nbuilder = {}")).toThrowError(
new InvalidBuilderError({}),
new InvalidBuilderError({} as unknown as string),
);
});

Expand All @@ -69,13 +69,13 @@ shared = true`);
new InvalidDriveFormatError("invalid"),
);
expect(() => parse("[drives.root]\nformat = true")).toThrowError(
new InvalidDriveFormatError(true),
new InvalidDriveFormatError(true as unknown as string),
);
expect(() => parse("[drives.root]\nformat = 10")).toThrowError(
new InvalidDriveFormatError(10),
new InvalidDriveFormatError(10 as unknown as string),
);
expect(() => parse("[drives.root]\nformat = {}")).toThrowError(
new InvalidDriveFormatError({}),
new InvalidDriveFormatError({} as unknown as string),
);
});

Expand All @@ -93,19 +93,21 @@ shared = true`);

it("invalid drive: invalid mount", () => {
expect(() => parse("[drives.data]\nmount = 42")).toThrowError(
new InvalidStringValueError(42),
new InvalidStringValueError(42 as unknown as string),
);
});

it("invalid empty drive: invalid fomat", () => {
expect(() =>
parse("[drives.data]\nbuilder = 'empty'\nformat = 42"),
).toThrowError(new InvalidEmptyDriveFormatError(42));
).toThrowError(
new InvalidEmptyDriveFormatError(42 as unknown as string),
);
});

it("invalid boolean value", () => {
expect(() => parse("[machine]\nno-rollup = 42")).toThrowError(
new InvalidBooleanValueError(42),
new InvalidBooleanValueError(42 as unknown as string),
);
});

Expand All @@ -117,7 +119,7 @@ shared = true`);
format = "ext2"
`;
expect(() => parse(invalidTarDrive)).toThrowError(
new InvalidStringValueError(42),
new InvalidStringValueError(42 as unknown as string),
);
});

Expand Down Expand Up @@ -150,7 +152,7 @@ shared = true`);
bootargs = ["no4lvl", "quiet", false]
`;
expect(() => parse(invalidConfig)).toThrowError(
new InvalidStringValueError(false),
new InvalidStringValueError(false as unknown as string),
);
});
});

0 comments on commit 381f9bc

Please sign in to comment.