improve error messages

This commit is contained in:
josc146 2023-06-15 21:57:54 +08:00
parent 21c3009945
commit d99488f22f
5 changed files with 24 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import (
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
@ -51,6 +52,10 @@ func (a *App) InstallPyDep(python string, cnMirror bool) (string, error) {
if python == "" {
python, err = GetPython()
if runtime.GOOS == "windows" {
python, err = filepath.Abs(python)
if err != nil {
return "", err
}
python = `"` + python + `"`
}
}

View File

@ -115,19 +115,11 @@ func GetPython() (string, error) {
if err != nil {
return "", errors.New("failed to unzip python")
} else {
python, err := filepath.Abs("py310/python.exe")
if err != nil {
return "", err
}
return python, nil
return "py310/python.exe", nil
}
}
} else {
python, err := filepath.Abs("py310/python.exe")
if err != nil {
return "", err
}
return python, nil
return "py310/python.exe", nil
}
case "darwin":
return "python3", nil

View File

@ -136,7 +136,7 @@
"Custom Python Path": "自定义Python路径",
"Custom Models Path": "自定义模型路径",
"Microsoft Visual C++ Redistributable is not installed, would you like to download it?": "微软VC++组件未安装, 是否下载?",
"Path Cannot Contain Space": "路径不能包含空格",
"File Path Cannot Contain Space": "文件路径不能包含空格",
"Failed to switch model, please try starting the program with administrator privileges or increasing your virtual memory.": "切换模型失败, 请尝试以管理员权限启动程序, 或增加你的虚拟内存",
"Current Strategy": "当前Strategy",
"MacOS is not yet supported for performing this operation, please do it manually.": "MacOS尚未支持此操作, 请手动执行",
@ -144,5 +144,6 @@
"On Linux system, you must manually install python dependencies.": "在Linux系统下, 你必须手动安装python依赖",
"Update completed, please restart the program.": "更新完成, 请重启程序",
"Are you sure you want to reset this page? It cannot be undone.": "你确定要重置本页吗?这无法撤销",
"Model file download is not complete": "模型文件下载未完成"
"Model file download is not complete": "模型文件下载未完成",
"Error": "错误"
}

View File

@ -78,8 +78,13 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
toast(depErrorMsg, { type: 'info', position: 'bottom-left' });
if (commonStore.platform != 'linux')
toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => {
InstallPyDep(commonStore.settings.customPythonPath, commonStore.settings.cnMirror);
InstallPyDep(commonStore.settings.customPythonPath, commonStore.settings.cnMirror).catch((e) => {
const errMsg = e.message || e;
toast(t('Error') + ' - ' + errMsg, { type: 'error' });
});
setTimeout(WindowShow, 1000);
}, {
autoClose: 8000
});
else
toastWithButton(t('On Linux system, you must manually install python dependencies.'), t('Check'), () => {
@ -131,7 +136,13 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
await exit(1000).catch(() => {
});
StartServer(commonStore.settings.customPythonPath, port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1');
StartServer(commonStore.settings.customPythonPath, port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1').catch((e) => {
const errMsg = e.message || e;
if (errMsg.includes('path contains space'))
toast(`${t('Error')} - ${t('File Path Cannot Contain Space')}`, { type: 'error' });
else
toast(t('Error') + ' - ' + errMsg, { type: 'error' });
});
setTimeout(WindowShow, 1000);
let timeoutCount = 6;

View File

@ -259,7 +259,7 @@ export const Configs: FC = observer(() => {
}).catch(e => {
const errMsg = e.message || e;
if (errMsg.includes('path contains space'))
toast(`${t('Convert Failed')} - ${t('Path Cannot Contain Space')}`, { type: 'error' });
toast(`${t('Convert Failed')} - ${t('File Path Cannot Contain Space')}`, { type: 'error' });
else
toast(`${t('Convert Failed')} - ${e.message || e}`, { type: 'error' });
});