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

doc: ProtocolError and PermissionDenied are for client bugs #644

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions qubes/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,13 @@ def fire_event_for_filter(self, iterable, **kwargs):
return apply_filters(iterable, self.fire_event_for_permission(**kwargs))

@staticmethod
def enforce(predicate):
"""An assert replacement, but works even with optimisations."""
def enforce(predicate: bool) -> None:
"""If predicate is false, raise an exception to terminate handling
the request.

This will raise :py:class:`PermissionDenied` if the predicate is false.
See the documentation of that class for details.
"""
if not predicate:
raise PermissionDenied()

Expand Down
25 changes: 23 additions & 2 deletions qubes/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,29 @@ def __str__(self):


class ProtocolError(AssertionError):
"""Raised when something is wrong with data received"""
"""Raised when something is wrong with data received.

This does not provide any useful information to the client making
the request. Therefore, it should only be raised if there is a client
*programming* error, such as passing an argument to a request that does
not take an argument. It should not be used to reject requests that are
valid, but which qubesd is refusing to process. Instead, raise a
subclass of :py:class:`QubesException` with a useful error message.

TODO: figure out when this class should be used, and when
:py:class:`PermissionDenied` should be used.
"""

class PermissionDenied(Exception):
"""Raised deliberately by handlers when we decide not to cooperate"""
"""Raised deliberately by handlers to indicate a malformed client request.

This does not provide any useful information to the client making
the request. Therefore, it should only be raised if there is a client
*programming* error, such as passing an argument to a request that does
not take an argument. It should not be used to reject requests that are
valid, but which qubesd is refusing to process. Instead, raise a
subclass of :py:class:`QubesException` with a useful error message.

TODO: figure out when this class should be used, and when
:py:class:`ProtocolError` should be used.
"""