fix: catch nitro exit process for a clearer message

This commit is contained in:
Louis 2023-11-22 21:49:23 +07:00
parent 8f76b7c3e0
commit d0c44f70f1
2 changed files with 40 additions and 36 deletions

View File

@ -45,8 +45,6 @@ function initModel(modelFile: string): Promise<InitModelResponse> {
.then(checkAndUnloadNitro)
// 2. Spawn the Nitro subprocess
.then(spawnNitroProcess)
// 3. Wait until the port is used (Nitro http server is up)
.then(() => tcpPortUsed.waitUntilUsed(PORT, 300, 30000))
// 4. Load the model into the Nitro subprocess (HTTP POST request)
.then(loadLLMModel)
// 5. Check if the model is loaded successfully
@ -165,7 +163,8 @@ function checkAndUnloadNitro() {
* Using child-process to spawn the process
* Should run exactly platform specified Nitro binary version
*/
function spawnNitroProcess() {
async function spawnNitroProcess(): Promise<void> {
return new Promise((resolve, reject) => {
let binaryFolder = path.join(__dirname, "nitro"); // Current directory by default
let binaryName;
@ -206,6 +205,11 @@ function spawnNitroProcess() {
subprocess.on("close", (code) => {
console.log(`child process exited with code ${code}`);
subprocess = null;
reject(`Nitro process exited. ${code ?? ""}`);
});
tcpPortUsed.waitUntilUsed(PORT, 300, 30000).then(() => {
resolve();
});
});
}

View File

@ -49,7 +49,7 @@ export function useActiveModel() {
console.debug('Init model: ', modelId)
const path = join('models', model.name, modelId)
const res = await initModel(path)
if (res?.error && modelId === activeModel?.id) {
if (res?.error && (!activeModel?.id || modelId === activeModel?.id)) {
const errorMessage = `${res.error}`
alert(errorMessage)
setStateModel(() => ({