Skip to content

Commit 8da8f88

Browse files
committed
(potentially neeeds protocol version bump???)
Removing the manual serialization of original_error makes it possible to compile buttplug without json at all (or at least with json function elided at link time) Care should be taken to ensure that the error_message field is still populated with a useful message, as the original_error field will not be serialized. So basically not sure this actually needs to go upstream.
1 parent cd84cf7 commit 8da8f88

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

  • crates/buttplug_core/src/message/v0

crates/buttplug_core/src/message/v0/error.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct ErrorV0 {
4545
#[serde(rename = "ErrorMessage")]
4646
#[getset(get = "pub")]
4747
error_message: String,
48-
#[serde(skip)]
48+
#[serde(rename = "OriginalError", skip_serializing_if = "Option::is_none")]
4949
original_error: Option<ButtplugError>,
5050
}
5151

@@ -88,10 +88,6 @@ impl ErrorV0 {
8888
if let Some(ref original_error) = self.original_error {
8989
original_error.clone()
9090
} else {
91-
// Try deserializing what's in the error_message field
92-
if let Ok(deserialized_msg) = serde_json::from_str(&self.error_message) {
93-
return deserialized_msg;
94-
}
9591
ButtplugError::from(self.clone())
9692
}
9793
}
@@ -108,9 +104,7 @@ impl From<ButtplugError> for ErrorV0 {
108104
ButtplugError::ButtplugHandshakeError { .. } => ErrorCode::ErrorHandshake,
109105
ButtplugError::ButtplugUnknownError { .. } => ErrorCode::ErrorUnknown,
110106
};
111-
// SAFETY: ButtplugError derives Serialize and contains only serializable fields.
112-
// Serialization failure would indicate a bug in the type definition, not a runtime condition.
113-
let msg = serde_json::to_string(&error).expect("ButtplugError derives Serialize");
107+
let msg = error.to_string();
114108
ErrorV0::new(code, &msg, Some(error))
115109
}
116110
}

0 commit comments

Comments
 (0)