Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
1 change: 1 addition & 0 deletions changelog.d/14191.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update docstrings of `SynapseError` and `FederationError` to bettter describe what they are used for and the effects of using them are.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor? Is .doc possibly for user-visible documentation changes rather than internal docstrings? (No strong opinions here.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably but they are experienced by Synapse admins in their logs. This gives at least some context even if it's in the code.

I'm going to opt to leave it until someone has a stronger opinion.

24 changes: 21 additions & 3 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ def __init__(self, location: bytes, http_code: int = http.FOUND):

class SynapseError(CodeMessageException):
"""A base exception type for matrix errors which have an errcode and error
message (as well as an HTTP status code).
message (as well as an HTTP status code). These often bubble all the way up to the
client API response so the error code and status often reach the client directly as
defined here. If the error doesn't make sense to present to a client, then it
probably shouldn't be a `SynapseError`. For example, if we contact another
homeserver over federation, we shouldn't automatically ferry response errors back to
the client on our end (a 500 from a remote server does not make sense to a client
when our server did not experience a 500).

Attributes:
errcode: Matrix error code e.g 'M_FORBIDDEN'
Expand Down Expand Up @@ -600,8 +606,20 @@ def cs_error(msg: str, code: str = Codes.UNKNOWN, **kwargs: Any) -> "JsonDict":


class FederationError(RuntimeError):
Comment thread
DMRobertson marked this conversation as resolved.
"""This class is used to inform remote homeservers about erroneous
PDUs they sent us.
"""
Raised when we process an erroneous PDU.

There are two kinds scenarios where this exception can be raised:
Comment thread
MadLittleMods marked this conversation as resolved.
Outdated

1. We may pull an invalid PDU from a remote homeserver (e.g. during backfill). We
raise this exception to signal an error to the rest of the application.
2. We may be pushed an invalid PDU as part of a `/send` transaction from a remote
homeserver. We raise so that we can respond to the transaction and include the
error string in the "PDU Processing Result". The message which will likely be
ignored by the remote homeserver and is not machine parse-able since it's just a
string.

TODO: In the future, we should split these usage scenarios into their own error types.

FATAL: The remote server could not interpret the source event.
(e.g., it was missing a required field)
Expand Down
3 changes: 3 additions & 0 deletions synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,11 @@ async def process_pdu(pdu: EventBase) -> JsonDict:
with nested_logging_context(event_id):
try:
await self._handle_received_pdu(origin, pdu)
# Construct a "PDU Processing Result"
return {}
except FederationError as e:
logger.warning("Error handling PDU %s: %s", event_id, e)
# Construct a "PDU Processing Result"
return {"error": str(e)}
except Exception as e:
f = failure.Failure()
Expand All @@ -496,6 +498,7 @@ async def process_pdu(pdu: EventBase) -> JsonDict:
event_id,
exc_info=(f.type, f.value, f.getTracebackObject()), # type: ignore
)
# Construct a "PDU Processing Result"
Comment thread
MadLittleMods marked this conversation as resolved.
Outdated
return {"error": str(e)}

await concurrently_execute(
Expand Down