Skip to content

Commit c5e05ce

Browse files
Peter/river exceptions not excepting (#161)
Why === We validate the errors which might have some schema like extra fields, then we toss them away like unwanted trash. This is bad. What changed ============ The RiverServiceException class is updated to accept and store the original deserialized RiverError object. Client sessions now pass this underlying_error when raising service exceptions, making the full error payload accessible. Test plan ========= Ran ai-infra with this. The CI/CD for that will catch anything and it's also like low key just adding stuff.
1 parent 3114c60 commit c5e05ce

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/replit_river/client_session.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ async def send_rpc(
252252
except Exception as e:
253253
raise RiverException("error_deserializer", str(e)) from e
254254
raise exception_from_message(error.code)(
255-
error.code, error.message, service_name, procedure_name
255+
error.code,
256+
error.message,
257+
service_name,
258+
procedure_name,
259+
underlying_error=error,
256260
)
257261
return response_deserializer(response["payload"])
258262
except RiverException as e:
@@ -338,7 +342,11 @@ async def send_upload(
338342
except Exception as e:
339343
raise RiverException("error_deserializer", str(e)) from e
340344
raise exception_from_message(error.code)(
341-
error.code, error.message, service_name, procedure_name
345+
error.code,
346+
error.message,
347+
service_name,
348+
procedure_name,
349+
underlying_error=error,
342350
)
343351

344352
return response_deserializer(response["payload"])

src/replit_river/error_schema.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ class RiverServiceException(RiverException):
5151
"""Exception raised by river as a result of a fault in the service running river."""
5252

5353
def __init__(
54-
self, code: str, message: str, service: str | None, procedure: str | None
54+
self,
55+
code: str,
56+
message: str,
57+
service: str | None,
58+
procedure: str | None,
59+
underlying_error: RiverError | None = None,
5560
) -> None:
5661
self.code = code
5762
self.message = message
5863
self.service = service
5964
self.procedure = procedure
65+
self.underlying_error = underlying_error
6066
service = service or "N/A"
6167
procedure = procedure or "N/A"
6268
msg = (

src/replit_river/v2/session.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,11 @@ async def send_rpc[R, A](
790790
except Exception as e:
791791
raise RiverException("error_deserializer", str(e)) from e
792792
raise exception_from_message(error.code)(
793-
error.code, error.message, service_name, procedure_name
793+
error.code,
794+
error.message,
795+
service_name,
796+
procedure_name,
797+
underlying_error=error,
794798
)
795799

796800
return response_deserializer(result["payload"])
@@ -899,7 +903,11 @@ async def send_upload[I, R, A](
899903
except Exception as e:
900904
raise RiverException("error_deserializer", str(e)) from e
901905
raise exception_from_message(error.code)(
902-
error.code, error.message, service_name, procedure_name
906+
error.code,
907+
error.message,
908+
service_name,
909+
procedure_name,
910+
underlying_error=error,
903911
)
904912

905913
return response_deserializer(result["payload"])

0 commit comments

Comments
 (0)