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

fix(framework) Update behaviour of _raise_if in ServerAppIo #4795

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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: 15 additions & 1 deletion src/py/flwr/server/superlink/driver/serverappio_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""ServerAppIo API servicer."""


import inspect
import threading
import time
from logging import DEBUG, INFO
Expand Down Expand Up @@ -345,5 +346,18 @@ def GetRunStatus(


def _raise_if(validation_error: bool, detail: str) -> None:
"""Raise a `ValueError` with a detailed message if a validation error occurs.

If `validation_error` is `True`, a `ValueError` will be raised with a message in the
format "Malformed <CallerFunctionName>Request: <detail>".
"""
if validation_error:
raise ValueError(f"Malformed PushTaskInsRequest: {detail}")
caller_frame = inspect.currentframe()
jafermarq marked this conversation as resolved.
Show resolved Hide resolved

caller_name = "UnknownFunction"
if caller_frame is not None:
f_back = caller_frame.f_back
if f_back is not None:
caller_name = f_back.f_code.co_name

raise ValueError(f"Malformed {caller_name}Request: {detail}")
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_raise_if_true() -> None:
# Assert
raise AssertionError()
except ValueError as err:
assert str(err) == "Malformed PushTaskInsRequest: test"
assert str(err) == "Malformed test_raise_if_trueRequest: test"
except Exception as err:
raise AssertionError() from err

Expand Down