chore: Better error message

This commit is contained in:
BluJ
2023-04-27 12:31:11 -06:00
parent aeb329341f
commit 1e01490778

View File

@@ -13,9 +13,10 @@ type Daemon<Ids extends string, Command extends string, Id extends string> = {
fn: () => Promise<CheckResult> | CheckResult
trigger?: Trigger
}
requires?: Exclude<Ids, Id>[]
requires: Exclude<Ids, Id>[]
}
type ErrorDuplicateId<Id extends string> = `The id "${Id}" is already used`
/**
* Used during the main of a function, it allows us to describe and ensure a set of daemons are running.
* With the dependency, we are using this like an init system, where we can ensure that a daemon is running
@@ -56,7 +57,12 @@ export class Daemons<Ids extends string> {
return new Daemons<never>(config.effects, config.started)
}
addDaemon<Id extends string, Command extends string>(
id: "" extends Id ? never : Id extends Ids ? never : Id,
// prettier-ignore
id:
"" extends Id ? never :
ErrorDuplicateId<Id> extends Id ? never :
Id extends Ids ? ErrorDuplicateId<Id> :
Id,
newDaemon: Omit<Daemon<Ids, Command, Id>, "id">,
) {
const daemons = ((this?.daemons ?? []) as any[]).concat({
@@ -98,7 +104,6 @@ export class Daemons<Ids extends string> {
}
resolve(child)
})
return child
})
}
return {