Extract "not in a chat" check into guard clause

This lets us remove a layer of indentation, and reveal the error
handling logic that was previously hidden below a really long block of
code.
This commit is contained in:
valadaptive
2023-12-25 03:19:08 -05:00
parent 4fc2f15448
commit 1029ad90a2

View File

@ -3015,8 +3015,18 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
quiet_prompt = main_api == 'novel' && !quietToLoud ? adjustNovelInstructionPrompt(quiet_prompt) : quiet_prompt; quiet_prompt = main_api == 'novel' && !quietToLoud ? adjustNovelInstructionPrompt(quiet_prompt) : quiet_prompt;
} }
if (true === dryRun || const isChatValid = online_status != 'no_connection' && this_chid != undefined && this_chid !== 'invalid-safety-id';
(online_status != 'no_connection' && this_chid != undefined && this_chid !== 'invalid-safety-id')) {
// We can't do anything because we're not in a chat right now. (Unless it's a dry run, in which case we need to
// assemble the prompt so we can count its tokens regardless of whether a chat is active.)
if (!dryRun && !isChatValid) {
if (this_chid === undefined || this_chid === 'invalid-safety-id') {
toastr.warning('Сharacter is not selected');
}
is_send_press = false;
return Promise.resolve();
}
let textareaText; let textareaText;
if (type !== 'regenerate' && type !== 'swipe' && type !== 'quiet' && !isImpersonate && !dryRun) { if (type !== 'regenerate' && type !== 'swipe' && type !== 'quiet' && !isImpersonate && !dryRun) {
is_send_press = true; is_send_press = true;
@ -3950,12 +3960,6 @@ async function Generate(type, { automatic_trigger, force_name2, quiet_prompt, qu
streamingProcessor = null; streamingProcessor = null;
throw exception; throw exception;
} }
} else { //generate's primary loop ends, after this is error handling for no-connection or safety-id
if (this_chid === undefined || this_chid === 'invalid-safety-id') {
toastr.warning('Сharacter is not selected');
}
is_send_press = false;
}
} }
function flushWIDepthInjections() { function flushWIDepthInjections() {