feat: add useful error assertion message
This commit is contained in:
+6
-1
@@ -22,7 +22,12 @@ export function provideContext<T>(fn: () => T): T {
|
||||
path,
|
||||
compose: createCachedGetter("compose", () =>
|
||||
path()
|
||||
.then(throwWhen((path): path is undefined => path === undefined))
|
||||
.then(
|
||||
throwWhen(
|
||||
(path): path is undefined => path === undefined,
|
||||
"Compose file cannot be found",
|
||||
),
|
||||
)
|
||||
.then(readCompose),
|
||||
),
|
||||
},
|
||||
|
||||
+7
-3
@@ -124,11 +124,15 @@ export async function waitForDeploymentRollout(
|
||||
|
||||
export function throwWhen<T, Narrowed extends T>(
|
||||
condition: (arg: T) => arg is Narrowed,
|
||||
message?: string,
|
||||
): (arg: T) => Exclude<T, Narrowed>;
|
||||
export function throwWhen<T>(condition: (arg: T) => unknown): (arg: T) => T;
|
||||
export function throwWhen<T>(condition: (arg: T) => unknown) {
|
||||
export function throwWhen<T>(
|
||||
condition: (arg: T) => unknown,
|
||||
message?: string,
|
||||
): (arg: T) => T;
|
||||
export function throwWhen<T>(condition: (arg: T) => unknown, message?: string) {
|
||||
return (arg: T) => {
|
||||
if (condition(arg)) throw new Error("Condition matched");
|
||||
if (condition(arg)) throw new Error(message ?? "Condition matched");
|
||||
return arg;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user