diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-04-13 14:14:57 +0000 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-04-14 12:47:32 +0000 |
commit | fd4d6afc778f633b0e4d3df3c478599d7cc1f7fe (patch) | |
tree | 853ce1abede5322e7897831a916ec08b1defcf0f /morphlib/builder.py | |
parent | 6fa273953645808be9fc81f52eb9093d8d76f15d (diff) | |
download | morph-fd4d6afc778f633b0e4d3df3c478599d7cc1f7fe.tar.gz |
Give more helpful error when stratum artifacts in cache are corrupted
I had a stratum artifact in my artifact cache which for some reason was
0 bytes long. When building a system that included this stratum, `morph
build` gave me the following output
2015-04-13 13:48:57 ERROR Traceback (most recent call last):
File "/src/morph/morphlib/builder.py", line 539, in build_and_cache
self.unpack_strata(fs_root)
File "/src/morph/morphlib/builder.py", line 600, in unpack_strata
chunks = [ArtifactCacheReference(c) for c in json.load(f)]
File "/usr/lib/python2.7/json/__init__.py", line 290, in load
**kw)
File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
With this patch, I get a better error:
ERROR: Corruption detected: No JSON object could be decoded while
loading
/src/build/cache/artifacts/8b4422c58ecb2a085b142fbba74b760f501f65d4b2885bf707994973230e0c58.stratum.build-essential-minimal
Change-Id: I0ad359901c5da75bd26d5a1a8108ef4e6f1d7708
Diffstat (limited to 'morphlib/builder.py')
-rw-r--r-- | morphlib/builder.py | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py index 04ebd149..1c016674 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -563,17 +563,33 @@ class SystemBuilder(BuilderBase): # pragma: no cover self.save_build_times() return self.source.artifacts.itervalues() + def load_stratum(self, stratum_artifact): + '''Load a stratum from the local artifact cache. + + Returns a list of ArtifactCacheReference instances for the chunks + contained in the stratum. + + ''' + cache = self.local_artifact_cache + with cache.get(stratum_artifact) as stratum_file: + try: + artifact_list = json.load(stratum_file, + encoding='unicode-escape') + except ValueError as e: + raise cliapp.AppException( + 'Corruption detected: %s while loading %s' % + (e, cache.artifact_filename(stratum_artifact))) + return [ArtifactCacheReference(a) for a in artifact_list] + def unpack_one_stratum(self, stratum_artifact, target): '''Unpack a single stratum into a target directory''' cache = self.local_artifact_cache - with cache.get(stratum_artifact) as stratum_file: - artifact_list = json.load(stratum_file, encoding='unicode-escape') - for chunk in (ArtifactCacheReference(a) for a in artifact_list): - self.app.status(msg='Unpacking chunk %(basename)s', - basename=chunk.basename(), chatty=True) - with cache.get(chunk) as chunk_file: - morphlib.bins.unpack_binary_from_file(chunk_file, target) + for chunk in self.load_stratum(stratum_artifact): + self.app.status(msg='Unpacking chunk %(basename)s', + basename=chunk.basename(), chatty=True) + with cache.get(chunk) as chunk_file: + morphlib.bins.unpack_binary_from_file(chunk_file, target) target_metadata = os.path.join( target, 'baserock', '%s.meta' % stratum_artifact.name) @@ -596,12 +612,10 @@ class SystemBuilder(BuilderBase): # pragma: no cover # download the chunk artifacts if necessary for stratum_artifact in self.source.dependencies: - f = self.local_artifact_cache.get(stratum_artifact) - chunks = [ArtifactCacheReference(c) for c in json.load(f)] + chunks = self.load_stratum(stratum_artifact) download_depends(chunks, self.local_artifact_cache, self.remote_artifact_cache) - f.close() # unpack it from the local artifact cache for stratum_artifact in self.source.dependencies: |