From 7f1cbc83361578d403afab8696e58493cf782b85 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Tue, 21 Feb 2023 22:52:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20except=20=E6=97=A0=E6=B3=95=E8=A7=A3?= =?UTF-8?q?=E5=8E=8B=E7=9A=84=E6=96=87=E4=BB=B6=E5=8C=85=20(#9677)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Aaron3S --- apps/ops/api/playbook.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/ops/api/playbook.py b/apps/ops/api/playbook.py index c26643fe5..b3c1fe564 100644 --- a/apps/ops/api/playbook.py +++ b/apps/ops/api/playbook.py @@ -6,6 +6,7 @@ from django.conf import settings from django.shortcuts import get_object_or_404 from rest_framework import status +from common.exceptions import JMSException from orgs.mixins.api import OrgBulkModelViewSet from ..exception import PlaybookNoValidEntry from ..models import Playbook @@ -39,7 +40,11 @@ class PlaybookViewSet(OrgBulkModelViewSet): if 'multipart/form-data' in self.request.headers['Content-Type']: src_path = os.path.join(settings.MEDIA_ROOT, instance.path.name) dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__()) - unzip_playbook(src_path, dest_path) + try: + unzip_playbook(src_path, dest_path) + except RuntimeError as e: + raise JMSException(code='invalid_playbook_file', detail={"msg": "Unzip failed"}) + if 'main.yml' not in os.listdir(dest_path): raise PlaybookNoValidEntry