invokeFunction argument typecheck

pull/690/head
Zef Hemel 2024-02-08 13:01:32 +01:00
parent a925212427
commit e1ac990de9
1 changed files with 11 additions and 0 deletions

View File

@ -81,6 +81,17 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
* @param args an array of arguments to pass to the function * @param args an array of arguments to pass to the function
*/ */
invokeFunction(name: string, args: any[]): Promise<any> { invokeFunction(name: string, args: any[]): Promise<any> {
// Some sanity type checks
if (typeof name !== "string") {
throw new Error(
`invokeFunction: function name should be a string, got ${typeof name}`,
);
}
if (!Array.isArray(args)) {
throw new Error(
`invokeFunction: args should be an array, got ${typeof args}`,
);
}
const [plugName, functionName] = name.split("."); const [plugName, functionName] = name.split(".");
if (!functionName) { if (!functionName) {
// Sanity check // Sanity check