[Added] Human readable error when we get a corrupted project

This commit is contained in:
Salvador E. Tropea 2023-05-17 11:09:24 -03:00
parent e7cde1164c
commit 7576bbd3b4
2 changed files with 10 additions and 2 deletions

View File

@ -17,7 +17,7 @@ from datetime import datetime
from shutil import copy2
from sys import exit, exc_info
from traceback import extract_stack, format_list, print_tb
from .misc import EXIT_BAD_ARGS, W_DATEFORMAT, W_UNKVAR, WRONG_INSTALL
from .misc import EXIT_BAD_ARGS, W_DATEFORMAT, W_UNKVAR, WRONG_INSTALL, CORRUPTED_PRO
from .log import get_logger
logger = get_logger(__name__)
@ -224,7 +224,10 @@ class GS(object):
# Get the text_variables
with open(GS.pro_file, 'rt') as f:
pro_text = f.read()
data = json.loads(pro_text)
try:
data = json.loads(pro_text)
except Exception:
GS.exit_with_error('Corrupted project {}'.format(GS.pro_file), CORRUPTED_PRO)
GS.pro_variables = data.get('text_variables', {})
logger.debug("Current text variables: {}".format(GS.pro_variables))
return GS.pro_variables

View File

@ -44,6 +44,7 @@ NETLIST_DIFF = 30
PS_SCH_PRINT = 31
DXF_SCH_PRINT = 32
HPGL_SCH_PRINT = 33
CORRUPTED_PRO = 34
error_level_to_name = ['NONE',
'INTERNAL_ERROR',
'WRONG_ARGUMENTS',
@ -75,6 +76,10 @@ error_level_to_name = ['NONE',
'MISSING_FILES',
'DIFF_TOO_BIG',
'NETLIST_DIFF',
'PS_SCH_PRINT',
'DXF_SCH_PRINT',
'HPGL_SCH_PRINT',
'CORRUPTED_PRO'
]
KICOST_SUBMODULE = '../submodules/KiCost/src/kicost'
EXAMPLE_CFG = 'example_template.kibot.yaml'