Merge pull request #2838 from SillyTavern/genraw-error-logging

Improve error handling of /genraw and /gen
This commit is contained in:
Cohee 2024-09-13 14:23:16 +03:00 committed by GitHub
commit 854541f4ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 5 deletions

View File

@ -3265,7 +3265,7 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy
} }
if (data.error) { if (data.error) {
throw new Error(data.error); throw new Error(data.response);
} }
const message = cleanUpMessage(extractMessageFromData(data), false, false, true); const message = cleanUpMessage(extractMessageFromData(data), false, false, true);
@ -4413,9 +4413,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
generatedPromptCache = ''; generatedPromptCache = '';
if (data?.response) { if (data?.response) {
toastr.error(data.response, 'API Error'); toastr.error(data.response, 'API Error', { preventDuplicates: true });
} }
throw data?.response; throw new Error(data?.response);
} }
//const getData = await response.json(); //const getData = await response.json();

View File

@ -2241,7 +2241,7 @@ function setEphemeralStopStrings(value) {
async function generateRawCallback(args, value) { async function generateRawCallback(args, value) {
if (!value) { if (!value) {
console.warn('WARN: No argument provided for /genraw command'); console.warn('WARN: No argument provided for /genraw command');
return; return '';
} }
// Prevent generate recursion // Prevent generate recursion
@ -2260,12 +2260,16 @@ async function generateRawCallback(args, value) {
setEphemeralStopStrings(resolveVariable(args?.stop)); setEphemeralStopStrings(resolveVariable(args?.stop));
const result = await generateRaw(value, '', isFalseBoolean(args?.instruct), quietToLoud, systemPrompt, length); const result = await generateRaw(value, '', isFalseBoolean(args?.instruct), quietToLoud, systemPrompt, length);
return result; return result;
} catch (err) {
console.error('Error on /genraw generation', err);
toastr.error(err.message, 'API Error', { preventDuplicates: true });
} finally { } finally {
if (lock) { if (lock) {
activateSendButtons(); activateSendButtons();
} }
flushEphemeralStoppingStrings(); flushEphemeralStoppingStrings();
} }
return '';
} }
/** /**
@ -2291,12 +2295,16 @@ async function generateCallback(args, value) {
const name = args?.name; const name = args?.name;
const result = await generateQuietPrompt(value, quietToLoud, false, '', name, length); const result = await generateQuietPrompt(value, quietToLoud, false, '', name, length);
return result; return result;
} catch (err) {
console.error('Error on /gen generation', err);
toastr.error(err.message, 'API Error', { preventDuplicates: true });
} finally { } finally {
if (lock) { if (lock) {
activateSendButtons(); activateSendButtons();
} }
flushEphemeralStoppingStrings(); flushEphemeralStoppingStrings();
} }
return '';
} }
/** /**

View File

@ -375,7 +375,9 @@ router.post('/generate', jsonParser, async function (request, response) {
} }
} }
} catch (error) { } 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); console.log('Endpoint error:', error);
if (!response.headersSent) { if (!response.headersSent) {