Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify error handling with the cloud storage #5389

Merged
merged 15 commits into from
Dec 8, 2022

Conversation

Marishka17
Copy link
Contributor

@Marishka17 Marishka17 commented Nov 30, 2022

Motivation and context

Closes issue 34
Added a general solution for checking bucket and file status instead of checking in all places. Exception information has become more user-friendly.

How has this been tested?

Added test

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

cvat/apps/engine/views.py Fixed Show fixed Hide fixed
cvat/apps/engine/views.py Fixed Show fixed Hide fixed
@Marishka17
Copy link
Contributor Author

/check

raise NotFound('The resource {} not found. It may have been deleted.'.format(self.name))
elif storage_status == Status.AVAILABLE:
raise
raise ValidationError(str(ex))

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
raise NotFound("The file '{}' not found on the cloud storage '{}'".format(key, self.name))
elif file_status == Status.FORBIDDEN:
raise PermissionDenied("Access to the file '{}' on the '{}' cloud storage is denied".format(key, self.name))
raise ValidationError(str(ex))

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
except (ValidationError, PermissionDenied, NotFound) as ex:
msg = str(ex) if not isinstance(ex, ValidationError) else \
'\n'.join([str(d) for d in ex.detail])
return Response(data=msg, status=ex.status_code)

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
cvat/apps/engine/views.py Fixed Show fixed Hide fixed
cvat/apps/engine/views.py Fixed Show fixed Hide fixed
@github-actions
Copy link
Contributor

github-actions bot commented Nov 30, 2022

✔️ All checks completed successfully
📄 See logs here

except (ValidationError, PermissionDenied, NotFound) as ex:
msg = str(ex) if not isinstance(ex, ValidationError) else \
'\n'.join([str(d) for d in ex.detail])
return Response(data=msg, status=ex.status_code)

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
except (ValidationError, PermissionDenied, NotFound) as ex:
msg = str(ex) if not isinstance(ex, ValidationError) else \
'\n'.join([str(d) for d in ex.detail])
return Response(data=msg, status=ex.status_code)

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
@Marishka17
Copy link
Contributor Author

/check

@github-actions
Copy link
Contributor

github-actions bot commented Dec 1, 2022

✔️ All checks completed successfully
📄 See logs here

slogger.cloud_storage[pk].info(msg)
return Response(data=msg, status=status.HTTP_404_NOT_FOUND)
return Response(data=msg, status=ex.status_code)

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
msg = str(ex) if not isinstance(ex, ValidationError) else \
'\n'.join([str(d) for d in ex.detail])
slogger.cloud_storage[pk].info(msg)
return Response(data=msg, status=ex.status_code)

Check warning

Code scanning / CodeQL

Information exposure through an exception

[Stack trace information](1) flows to this location and may be exposed to an external user.
@Marishka17 Marishka17 changed the title [WIP] Unify error handling with the cloud storage Unify error handling with the cloud storage Dec 1, 2022
@sizov-kirill sizov-kirill self-requested a review December 5, 2022 11:29
# [ErrorDetail(string="...", code=\'invalid\')]\n'
parsed_msg = msg.split('string=')[1].split(', code=')[0].strip("\"")
elif 'PermissionDenied' in msg:
# msg like 'rest_framework.exceptions.PermissionDenied: ... \n'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will prefer to have a more general solution. For example,

if msg.startswith('rest_framework.exceptions.'):
    parsed_msg = msg.split(':')[1].strip()

@@ -110,17 +110,34 @@ def parse_specific_attributes(specific_attributes):
} if parsed_specific_attributes else dict()


def parse_exception_message(msg):
parsed_msg = msg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to handle a case when msg is empty by a reason. Please resolve a conflict and see the case.

Copy link
Contributor

@sizov-kirill sizov-kirill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good to me, but I have few questions about these changes. Also agree with Nikita's comments

P.S.: also have question that not related with this PR but related with the CloudStorageViewSet, why somewhere we use HTTPResponse and somewhere Response? Is it possible to use only one "response" class?

cvat/apps/engine/views.py Show resolved Hide resolved
cvat/apps/engine/views.py Show resolved Hide resolved
@nmanovic nmanovic merged commit c9f214a into develop Dec 8, 2022
@nmanovic nmanovic deleted the mk/improve_exception_message branch December 8, 2022 18:32
@nmanovic nmanovic mentioned this pull request Dec 12, 2022
mikhail-treskin pushed a commit to retailnext/cvat that referenced this pull request Jul 1, 2023
Added a general solution for checking bucket and file status instead of
checking in all places. Exception information has become more
user-friendly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants