Skip to content

Commit

Permalink
Better error message when kicad_common.json is corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Apr 2, 2024
1 parent c75951d commit e22acbb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2.3.1] - Unreleased
### Changed
- Better error message when kicad_common.json is corrupted (INTI-CMNB/KiBot#599)


## [2.3.0] - 2024-03-21
### Added
- Support for KiCad 8
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
kiauto (2.3.1-1) UNRELEASED; urgency=medium

* Next release

-- Salvador Eduardo Tropea <[email protected]> Tue, 02 Apr 2024 11:16:39 -0300

kiauto (2.3.0-1) stable; urgency=medium

* KiCad 8.0.0 support
Expand Down
2 changes: 1 addition & 1 deletion kiauto/file_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def create_kicad_config(cfg):
kiconf['system'] = {"editor_name": "/bin/cat"}
# Copy the environment vars if available
if cfg.conf_kicad_bkp:
vars = Config.get_config_vars_json(cfg.conf_kicad_bkp)
vars = Config.get_config_vars_json(cfg.conf_kicad_bkp, logger)
if vars:
kiconf['environment']['vars'] = vars
text_file.write(json.dumps(kiconf))
Expand Down
14 changes: 10 additions & 4 deletions kiauto/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
READ_ONLY_PROBLEM = 17
WONT_OVERWRITE = 18
KICAD_CLI_ERROR = 19
CORRUPTED_CONFIG = 20
# Wait 60 s to pcbnew/eeschema window to be present
WAIT_START = 60
# Name for testing versions
Expand Down Expand Up @@ -291,7 +292,7 @@ def __init__(self, logger, input_file=None, args=None, is_pcbnew=False):
def load_kicad_environment(self, logger):
self.env = {}
if self.conf_kicad_json:
env = self.get_config_vars_json(self.conf_kicad)
env = self.get_config_vars_json(self.conf_kicad, logger)
if env:
self.env = env
else:
Expand All @@ -302,9 +303,14 @@ def load_kicad_environment(self, logger):
logger.debug('KiCad environment: '+str(self.env))

@staticmethod
def get_config_vars_json(file):
def get_config_vars_json(file, logger):
with open(file, "rt") as f:
data = json.load(f)
raw_data = f.read()
try:
data = json.loads(raw_data)
except json.decoder.JSONDecodeError:
logger.error(f"Corrupted KiCad config file `{file}`:\n{raw_data}")
exit(CORRUPTED_CONFIG)
if 'environment' in data and 'vars' in data['environment']:
return data['environment']['vars']
return None
Expand Down Expand Up @@ -348,4 +354,4 @@ def get_en_locale(logger):
__email__ = '[email protected]'
__status__ = 'stable'
__url__ = 'https:/INTI-CMNB/KiAuto/'
__version__ = '2.3.0'
__version__ = '2.3.1'

0 comments on commit e22acbb

Please sign in to comment.