From eef4094f569e3fb8c84a577cc5f62e083f8f714d Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 18 Feb 2019 13:02:46 -0500 Subject: [PATCH] Catch parsing errors in image API Fixes https://sentry.io/organizations/coreos/issues/664440779/ --- endpoints/api/image.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/endpoints/api/image.py b/endpoints/api/image.py index 9fb3c5c92..3a9dcd82c 100644 --- a/endpoints/api/image.py +++ b/endpoints/api/image.py @@ -8,11 +8,18 @@ from endpoints.exception import NotFound def image_dict(image, with_history=False, with_tags=False): + parsed_command = None + if image.command: + try: + parsed_command = json.loads(image.command) + except (ValueError, TypeError): + parsed_command = {'error': 'Could not parse command'} + image_data = { 'id': image.docker_image_id, 'created': format_date(image.created), 'comment': image.comment, - 'command': json.loads(image.command) if image.command else None, + 'command': parsed_command, 'size': image.image_size, 'uploading': image.uploading, 'sort_index': len(image.parents),