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

Improve the error shown when an RPC return value fails serialisation #1966

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 11 additions & 5 deletions artiq/coredevice/comm_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,17 @@ def service(obj, attr, value): return setattr(obj, attr, value)
else:
logger.debug("rpc service: %d %r %r = %r",
service_id, args, kwargs, result)
self._write_header(Request.RPCReply)
self._write_bytes(return_tags)
self._send_rpc_value(bytearray(return_tags),
result, result, service)
self._flush()
try:
self._write_header(Request.RPCReply)
self._write_bytes(return_tags)
self._send_rpc_value(bytearray(return_tags),
Copy link
Member

Choose a reason for hiding this comment

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

I would at least narrow down the try block to only the function susceptible to fail, which is only this line AFAICT?
Can't the code that raises the error initially simply include the function information in its exception? Why is it not in the traceback anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is it not in the traceback anyway?

This is after the function being called by the RPC has returned so it's not on the call stack anymore.

Can't the code that raises the error initially simply include the function information in its exception?

We could do, where ever it's an explicitly raised exception. In fact we already do in one instance, but most of the raised exceptions don't include this information. I like centralising these kind of things so that as more raises get added you don't have to remember to add it each time. And this also has the advantage of adding this information to any unexpected errors.

I would at least narrow down the try block to only the function susceptible to fail, which is only this line AFAICT?

I agree that is the most likely function to fail. But I was feeling defensive when I wrote this and I can't see any harm in increasing the scope of this try block. The original exception is preserved as the cause of the exception raised here so we're not losing any information and the context might just be useful.

result, result, service)
self._flush()
except Exception as ex:
raise RuntimeError(
f"Failed to return RPC value for RPC [{service_id}]{service!r} "
f"return_tags={return_tags}: {ex}"
) from ex

def _serve_exception(self, embedding_map, symbolizer, demangler):
exception_count = self._read_int32()
Expand Down