From 56869a2dc28e5ce5910839062a4c7bb145430041 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sun, 30 Jul 2023 01:21:19 +0200 Subject: [PATCH] Make error of function json parsing more descriptive --- src/funcitonManager.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/funcitonManager.ts b/src/funcitonManager.ts index cbc2c99..008c14e 100644 --- a/src/funcitonManager.ts +++ b/src/funcitonManager.ts @@ -61,9 +61,14 @@ export default class FunctionManager { } public handleFunction(request: ChatCompletionRequestMessageFunctionCall) { - - const parsedArguments = JSON.parse(request.arguments ?? ""); - return this.store.get(request.name ?? "")?.execute(parsedArguments); + try { + const parsedArguments = JSON.parse(request.arguments ?? ""); + return this.store.get(request.name ?? "")?.execute(parsedArguments); + } + catch (e) { + console.error("Function arguments raw: " + request.arguments); + throw new Error(`Failed to parse the function JSON arguments when running function [${request.name}]`, {cause: e}); + } } }