Preserve an error log if the installation failed; Include the starting timestamp in the log

This commit is contained in:
cmdr2 2022-10-04 14:48:16 +05:30
parent 2174788514
commit abcab9bce5
4 changed files with 18 additions and 6 deletions

View File

@ -1,5 +1,7 @@
import subprocess
import sys
import shutil
import time
from installer import app
@ -27,8 +29,9 @@ def log(msg):
app.log_file.write(bytes(msg + "\n", 'utf-8'))
app.log_file.flush()
def show_install_error(error_msg):
log(f'''
def fail_with_install_error(error_msg):
try:
log(f'''
Error: {error_msg}. Sorry about that, please try to:
1. Run this installer again.
@ -36,3 +39,10 @@ Error: {error_msg}. Sorry about that, please try to:
3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB
4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues
Thanks!''')
ts = int(time.time())
shutil.copy(app.LOG_FILE_NAME, f'error-{ts}.log')
except:
pass
exit(1)

View File

@ -1,8 +1,10 @@
import os
import sys
from datetime import datetime
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from installer import helpers
from installer.tasks import (
fetch_project_repo,
apply_project_update,
@ -15,6 +17,8 @@ tasks = [
fetch_stable_diffusion_repo,
]
helpers.log(f'Starting Stable Diffusion UI at {datetime.now().strftime("%d/%m/%Y %H:%M:%S")}')
def run_tasks():
for task in tasks:
task.run()

View File

@ -20,7 +20,6 @@ def run():
if helpers.run(f'git clone {app.PROJECT_REPO_URL} "{app.project_repo_dir_path}"'):
helpers.log("Downloaded Stable Diffusion UI")
else:
helpers.show_install_error(error_msg="Could not download Stable Diffusion UI")
exit(1)
helpers.fail_with_install_error(error_msg="Could not download Stable Diffusion UI")
helpers.run(f'git -c advice.detachedHead=false checkout "{branch_name}"', run_in_folder=app.project_repo_dir_path)

View File

@ -32,8 +32,7 @@ def fetch_repo():
if helpers.run(f'git clone {app.STABLE_DIFFUSION_REPO_URL} "{app.stable_diffusion_repo_dir_path}"'):
helpers.log("Downloaded Stable Diffusion")
else:
helpers.show_install_error(error_msg="Could not download Stable Diffusion")
exit(1)
helpers.fail_with_install_error(error_msg="Could not download Stable Diffusion")
helpers.run(f'git -c advice.detachedHead=false checkout "{commit_id}"', run_in_folder=app.stable_diffusion_repo_dir_path)