Skip to content

Commit 1521bea

Browse files
committed
ldk-server-client: rename uniffi error field message -> reason
UniFFI's Kotlin generator emits struct-variant errors as subclasses of Throwable, and a constructor property named `message` collides with Throwable.message, producing a compile error on the generated ldk_server_client.kt. Renaming the field to `reason` sidesteps the clash without changing the FFI surface meaningfully. No behavior change; Display output now reads "Invalid request: <reason>" etc. All existing unit tests still pass. Co-Authored-By: HAL 9000
1 parent f60962b commit 1521bea

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

ldk-server-client/src/uniffi_types.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,31 @@ use crate::error::{LdkServerError, LdkServerErrorCode};
3939
/// for client-side / unknown errors.
4040
#[derive(Debug, thiserror::Error, uniffi::Error)]
4141
pub enum LdkServerClientError {
42-
#[error("Invalid request: {message}")]
43-
InvalidRequest { message: String },
44-
#[error("Authentication failed: {message}")]
45-
AuthenticationFailed { message: String },
46-
#[error("Lightning error: {message}")]
47-
LightningError { message: String },
48-
#[error("Internal server error: {message}")]
49-
InternalServerError { message: String },
50-
#[error("Internal error: {message}")]
51-
InternalError { message: String },
42+
#[error("Invalid request: {reason}")]
43+
InvalidRequest { reason: String },
44+
#[error("Authentication failed: {reason}")]
45+
AuthenticationFailed { reason: String },
46+
#[error("Lightning error: {reason}")]
47+
LightningError { reason: String },
48+
#[error("Internal server error: {reason}")]
49+
InternalServerError { reason: String },
50+
#[error("Internal error: {reason}")]
51+
InternalError { reason: String },
5252
}
5353

5454
impl From<LdkServerError> for LdkServerClientError {
5555
fn from(err: LdkServerError) -> Self {
56-
let message = err.message;
56+
// NOTE: the field is deliberately named `reason` rather than `message`: UniFFI's
57+
// Kotlin generator emits struct-variant errors as subclasses of `Throwable`, and a
58+
// constructor property called `message` collides with Throwable's own `message`
59+
// property, producing a compile error on the generated code. `reason` sidesteps that.
60+
let reason = err.message;
5761
match err.error_code {
58-
LdkServerErrorCode::InvalidRequestError => Self::InvalidRequest { message },
59-
LdkServerErrorCode::AuthError => Self::AuthenticationFailed { message },
60-
LdkServerErrorCode::LightningError => Self::LightningError { message },
61-
LdkServerErrorCode::InternalServerError => Self::InternalServerError { message },
62-
LdkServerErrorCode::InternalError => Self::InternalError { message },
62+
LdkServerErrorCode::InvalidRequestError => Self::InvalidRequest { reason },
63+
LdkServerErrorCode::AuthError => Self::AuthenticationFailed { reason },
64+
LdkServerErrorCode::LightningError => Self::LightningError { reason },
65+
LdkServerErrorCode::InternalServerError => Self::InternalServerError { reason },
66+
LdkServerErrorCode::InternalError => Self::InternalError { reason },
6367
}
6468
}
6569
}
@@ -354,7 +358,7 @@ impl TryFrom<UnifiedSendResponse> for UnifiedSendResult {
354358
Some(PaymentResult::Bolt11PaymentId(payment_id)) => Ok(Self::Bolt11 { payment_id }),
355359
Some(PaymentResult::Bolt12PaymentId(payment_id)) => Ok(Self::Bolt12 { payment_id }),
356360
None => Err(LdkServerClientError::InternalError {
357-
message: "server returned UnifiedSendResponse with no payment_result".to_string(),
361+
reason: "server returned UnifiedSendResponse with no payment_result".to_string(),
358362
}),
359363
}
360364
}
@@ -526,7 +530,7 @@ impl LdkServerClientUni {
526530
base_url: String, api_key: String, server_cert_pem: String,
527531
) -> Result<Arc<Self>, LdkServerClientError> {
528532
let inner = LdkServerClient::new(base_url, api_key, server_cert_pem.as_bytes())
529-
.map_err(|message| LdkServerClientError::InvalidRequest { message })?;
533+
.map_err(|reason| LdkServerClientError::InvalidRequest { reason })?;
530534
Ok(Arc::new(Self { inner }))
531535
}
532536

0 commit comments

Comments
 (0)