Skip to content

Commit

Permalink
Make the message prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Zhiltsov committed Mar 10, 2021
1 parent 7acfb04 commit 0d413b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
12 changes: 6 additions & 6 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ def convert_attrs(label, cvat_attrs):

return item_anno

class CvatImportError(Exception):
pass

def match_dm_item(item, task_data, root_hint=None):
is_video = task_data.meta['task']['mode'] == 'interpolation'

Expand All @@ -610,8 +613,8 @@ def match_dm_item(item, task_data, root_hint=None):
frame_number = cast(osp.basename(item.id)[len('frame_'):], int)

if not frame_number in task_data.frame_info:
raise Exception("Could not match item id: '%s' with any task frame" %
item.id)
raise CvatImportError("Could not match item id: "
"'%s' with any task frame" % item.id)
return frame_number

def find_dataset_root(dm_dataset, task_data):
Expand All @@ -626,9 +629,6 @@ def find_dataset_root(dm_dataset, task_data):
prefix = prefix[:-1]
return prefix

class CvatImportError(Exception):
pass

def import_dm_annotations(dm_dataset, task_data):
shapes = {
datumaro.AnnotationType.bbox: ShapeType.RECTANGLE,
Expand Down Expand Up @@ -692,4 +692,4 @@ def import_dm_annotations(dm_dataset, task_data):
))
except Exception as e:
raise CvatImportError("Image {}: can't import annotation "
"#{} ({}): {}".format(item.id, idx, type(ann), e))
"#{} ({}): {}".format(item.id, idx, ann.type.name, e))
13 changes: 12 additions & 1 deletion cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import cvat.apps.dataset_manager as dm
import cvat.apps.dataset_manager.views # pylint: disable=unused-import
from cvat.apps.authentication import auth
from cvat.apps.dataset_manager.bindings import CvatImportError
from cvat.apps.dataset_manager.serializers import DatasetFormatsSerializer
from cvat.apps.engine.frame_provider import FrameProvider
from cvat.apps.engine.models import (
Expand Down Expand Up @@ -1030,7 +1031,17 @@ def _import_annotations(request, rq_id, rq_func, pk, format_name):
os.remove(rq_job.meta['tmp_file'])
exc_info = str(rq_job.exc_info)
rq_job.delete()
return Response(data=exc_info, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

# RQ adds a prefix with exception class name
import_error_prefix = '{}.{}'.format(
CvatImportError.__module__, CvatImportError.__name__)
if exc_info.startswith(import_error_prefix):
exc_info = exc_info.replace(import_error_prefix + ': ', '')
return Response(data=exc_info,
status=status.HTTP_400_BAD_REQUEST)
else:
return Response(data=exc_info,
status=status.HTTP_500_INTERNAL_SERVER_ERROR)

return Response(status=status.HTTP_202_ACCEPTED)

Expand Down

0 comments on commit 0d413b5

Please sign in to comment.