From f5b68893d097d466d555eae68216cc23195b3651 Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Thu, 12 Sep 2024 22:41:53 +0200 Subject: [PATCH 1/5] Improve error handling of /genraw and /gen - /generate TC backend returns more status/error texts - Fix /genraw and /gen returning null/undefined - Logging errors on /genraw if backend throws an error - Fixes #2836 --- public/script.js | 2 +- public/scripts/slash-commands.js | 10 +++++++++- src/endpoints/backends/text-completions.js | 4 +++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 0305a68e7..4228d646c 100644 --- a/public/script.js +++ b/public/script.js @@ -3265,7 +3265,7 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy } if (data.error) { - throw new Error(data.error); + throw new Error(data.response); } const message = cleanUpMessage(extractMessageFromData(data), false, false, true); diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 68f001359..18b04a172 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2241,7 +2241,7 @@ function setEphemeralStopStrings(value) { async function generateRawCallback(args, value) { if (!value) { console.warn('WARN: No argument provided for /genraw command'); - return; + return ''; } // Prevent generate recursion @@ -2260,12 +2260,16 @@ async function generateRawCallback(args, value) { setEphemeralStopStrings(resolveVariable(args?.stop)); const result = await generateRaw(value, '', isFalseBoolean(args?.instruct), quietToLoud, systemPrompt, length); return result; + } catch (err) { + console.error('Error on /genraw generation', err); + toastr.error(err.message, 'Error on Generate'); } finally { if (lock) { activateSendButtons(); } flushEphemeralStoppingStrings(); } + return ''; } /** @@ -2291,12 +2295,16 @@ async function generateCallback(args, value) { const name = args?.name; const result = await generateQuietPrompt(value, quietToLoud, false, '', name, length); return result; + } catch (err) { + console.error('Error on /genraw generation', err); + toastr.error(err.message, 'Error on Generate'); } finally { if (lock) { activateSendButtons(); } flushEphemeralStoppingStrings(); } + return ''; } /** diff --git a/src/endpoints/backends/text-completions.js b/src/endpoints/backends/text-completions.js index ba113f2fd..06f9e0325 100644 --- a/src/endpoints/backends/text-completions.js +++ b/src/endpoints/backends/text-completions.js @@ -375,7 +375,9 @@ router.post('/generate', jsonParser, async function (request, response) { } } } catch (error) { - let value = { error: true, status: error?.status, response: error?.statusText }; + const status = error?.status ?? error?.code ?? 'UNKNOWN'; + const text = error?.error ?? error?.statusText ?? error?.message ?? 'Unknown error on /generate endpoint'; + let value = { error: true, status: status, response: text }; console.log('Endpoint error:', error); if (!response.headersSent) { From 88fab65a8f9895098614f0a07af71fb88ac0d4cd Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:01:59 +0000 Subject: [PATCH 2/5] Fix /gen log --- public/scripts/slash-commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 18b04a172..c1215f310 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2261,7 +2261,7 @@ async function generateRawCallback(args, value) { const result = await generateRaw(value, '', isFalseBoolean(args?.instruct), quietToLoud, systemPrompt, length); return result; } catch (err) { - console.error('Error on /genraw generation', err); + console.error('Error on /gen generation', err); toastr.error(err.message, 'Error on Generate'); } finally { if (lock) { From 0aede54cf1f69229ae6e7a1b681535e63f0082a3 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:10:24 +0000 Subject: [PATCH 3/5] Fix throw on /gen --- public/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/script.js b/public/script.js index 4228d646c..3acb6f33f 100644 --- a/public/script.js +++ b/public/script.js @@ -4415,7 +4415,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro if (data?.response) { toastr.error(data.response, 'API Error'); } - throw data?.response; + throw new Error(data?.response); } //const getData = await response.json(); From 620847c4d6a971e27c6b370cd31f24b927d07efc Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:12:41 +0000 Subject: [PATCH 4/5] Fixed logs --- public/scripts/slash-commands.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index c1215f310..08dd6744c 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2261,7 +2261,7 @@ async function generateRawCallback(args, value) { const result = await generateRaw(value, '', isFalseBoolean(args?.instruct), quietToLoud, systemPrompt, length); return result; } catch (err) { - console.error('Error on /gen generation', err); + console.error('Error on /genraw generation', err); toastr.error(err.message, 'Error on Generate'); } finally { if (lock) { @@ -2296,7 +2296,7 @@ async function generateCallback(args, value) { const result = await generateQuietPrompt(value, quietToLoud, false, '', name, length); return result; } catch (err) { - console.error('Error on /genraw generation', err); + console.error('Error on /gen generation', err); toastr.error(err.message, 'Error on Generate'); } finally { if (lock) { From 8dd7a97eb37922a324d2610d28ec60b9aa6806db Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 13 Sep 2024 11:22:12 +0000 Subject: [PATCH 5/5] Prevent duplicate toasts --- public/script.js | 2 +- public/scripts/slash-commands.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/script.js b/public/script.js index 3acb6f33f..e512ec774 100644 --- a/public/script.js +++ b/public/script.js @@ -4413,7 +4413,7 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro generatedPromptCache = ''; if (data?.response) { - toastr.error(data.response, 'API Error'); + toastr.error(data.response, 'API Error', { preventDuplicates: true }); } throw new Error(data?.response); } diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 08dd6744c..201dcb122 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -2262,7 +2262,7 @@ async function generateRawCallback(args, value) { return result; } catch (err) { console.error('Error on /genraw generation', err); - toastr.error(err.message, 'Error on Generate'); + toastr.error(err.message, 'API Error', { preventDuplicates: true }); } finally { if (lock) { activateSendButtons(); @@ -2297,7 +2297,7 @@ async function generateCallback(args, value) { return result; } catch (err) { console.error('Error on /gen generation', err); - toastr.error(err.message, 'Error on Generate'); + toastr.error(err.message, 'API Error', { preventDuplicates: true }); } finally { if (lock) { activateSendButtons();