Skip to content

Commit 99e74a3

Browse files
committed
fix(rivetkit): preserve bridge error messages
1 parent 7764046 commit 99e74a3

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

rivetkit-typescript/packages/rivetkit-napi/src/actor_context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ impl ActorContext {
341341
.verify(&self.inner, bearer_token.as_deref())
342342
.await
343343
.map_err(|error| {
344+
let message = error.to_string();
344345
napi_anyhow_error(error.context(BridgeRivetErrorContext {
346+
message: Some(message),
345347
public_: Some(true),
346348
status_code: Some(401),
347349
}))

rivetkit-typescript/packages/rivetkit-napi/src/actor_factory.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ struct BridgeRivetErrorPayload {
257257

258258
#[derive(Debug)]
259259
pub(crate) struct BridgeRivetErrorContext {
260+
pub message: Option<String>,
260261
pub public_: Option<bool>,
261262
pub status_code: Option<u16>,
262263
}
@@ -267,11 +268,10 @@ static BRIDGE_RIVET_ERROR_SCHEMAS: LazyLock<
267268

268269
impl std::fmt::Display for BridgeRivetErrorContext {
269270
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
270-
write!(
271-
f,
272-
"bridge rivet error context public={:?} status_code={:?}",
273-
self.public_, self.status_code
274-
)
271+
match &self.message {
272+
Some(message) => f.write_str(message),
273+
None => f.write_str("bridged RivetError"),
274+
}
275275
}
276276
}
277277

@@ -994,12 +994,14 @@ fn parse_bridge_rivet_error(reason: &str) -> Option<anyhow::Error> {
994994
.metadata
995995
.as_ref()
996996
.and_then(|metadata| serde_json::value::to_raw_value(metadata).ok());
997+
let message = payload.message;
997998
let error = anyhow::Error::new(rivet_error::RivetError {
998999
schema,
9991000
meta,
1000-
message: Some(payload.message),
1001+
message: Some(message.clone()),
10011002
});
10021003
Some(error.context(BridgeRivetErrorContext {
1004+
message: Some(message),
10031005
public_: payload.public_,
10041006
status_code: payload.status_code,
10051007
}))

rivetkit-typescript/packages/rivetkit-napi/tests/actor_factory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ mod moved_tests {
7373
let first = parse_bridge_rivet_error(&reason).expect("first parse should succeed");
7474
let second = parse_bridge_rivet_error(&reason).expect("second parse should succeed");
7575

76+
assert_eq!(first.to_string(), "same message");
7677
assert_eq!(schema_ptr(&first), schema_ptr(&second));
7778
}
7879

rivetkit-typescript/packages/rivetkit-wasm/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ struct BridgeRivetErrorPayload {
7171

7272
#[derive(Debug)]
7373
struct BridgeRivetErrorContext {
74+
message: Option<String>,
7475
public_: Option<bool>,
7576
status_code: Option<u16>,
7677
}
7778

7879
impl std::fmt::Display for BridgeRivetErrorContext {
7980
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80-
write!(
81-
f,
82-
"bridge rivet error context public={:?} status_code={:?}",
83-
self.public_, self.status_code
84-
)
81+
match &self.message {
82+
Some(message) => f.write_str(message),
83+
None => f.write_str("bridged RivetError"),
84+
}
8585
}
8686
}
8787

@@ -2700,12 +2700,14 @@ fn parse_bridge_rivet_error(reason: &str) -> Option<anyhow::Error> {
27002700
.metadata
27012701
.as_ref()
27022702
.and_then(|metadata| serde_json::value::to_raw_value(metadata).ok());
2703+
let message = payload.message;
27032704
let error = anyhow::Error::new(RivetTransportError {
27042705
schema,
27052706
meta,
2706-
message: Some(payload.message),
2707+
message: Some(message.clone()),
27072708
});
27082709
Some(error.context(BridgeRivetErrorContext {
2710+
message: Some(message),
27092711
public_: payload.public_,
27102712
status_code: payload.status_code,
27112713
}))
@@ -2872,6 +2874,8 @@ mod tests {
28722874
let first = parse_bridge_rivet_error(&reason).expect("bridge error should decode");
28732875
let first_schema = transport_schema(&first) as *const RivetErrorSchema;
28742876

2877+
assert_eq!(first.to_string(), "same payload message");
2878+
28752879
for _ in 0..100 {
28762880
let error = parse_bridge_rivet_error(&reason).expect("bridge error should decode");
28772881
let schema = transport_schema(&error) as *const RivetErrorSchema;

0 commit comments

Comments
 (0)