From 7576bbd3b45e909490967d601e9e2c2eb45f1e85 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 17 May 2023 11:09:24 -0300 Subject: [PATCH] [Added] Human readable error when we get a corrupted project --- kibot/gs.py | 7 +++++-- kibot/misc.py | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/kibot/gs.py b/kibot/gs.py index c94434a1..b823b1f9 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -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 diff --git a/kibot/misc.py b/kibot/misc.py index c9cec855..b2bffafa 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -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'