nautechsystems/nautilus_trader · error
Failed to build BybitRepayParams
Error message
Failed to build BybitRepayParams
What it means
`repay` builds `BybitRepayParams` and unwraps `build()` with `expect`. derive_builder's `build()` fails only on missing required fields, so the panic means a non-optional field of `BybitRepayParams` was never set on the builder — an internal invariant treated as unrecoverable.
Source
Thrown at crates/adapters/bybit/src/http/client.rs:1482
/// # References
///
/// - <https://bybit-exchange.github.io/docs/v5/account/repay>
pub async fn repay(
&self,
coin: Option<&str>,
amount: Option<&str>,
) -> Result<BybitRepayResponse, BybitHttpError> {
let mut builder = BybitRepayParamsBuilder::default();
if let Some(coin) = coin {
builder.coin(coin.to_string());
}
if let Some(amt) = amount {
builder.amount(amt.to_string());
}
let params = builder.build().expect("Failed to build BybitRepayParams");
if let Ok(params_json) = serde_json::to_string(¶ms) {
log::debug!("Repay request params: {params_json}");
}
let body = serde_json::to_vec(¶ms)?;
let result = self
.send_request::<_, ()>(Method::POST, "/v5/account/repay", None, Some(body), true)
.await;
if let Err(ref e) = result
&& let Ok(params_json) = serde_json::to_string(¶ms)
{
log::error!("Repay request failed with params {params_json}: {e}");
}
result
}View on GitHub (pinned to 18893faf8b)
Solutions
- Set every non-Option field on the builder before `.build()`
- Convert the `expect` into `?` mapping to `BybitHttpError`
- Re-check the builder chain after crate or Bybit API upgrades
- File a bug if it panics via the public `repay` call
Example fix
// before
let params = builder.build().expect("Failed to build BybitRepayParams");
// after
let params = builder.build().map_err(BybitHttpError::InvalidParams)?; Defensive patterns
Strategy: validation
Validate before calling
// Validate required repay fields before the call
assert!(!coin.is_empty(), "coin is required");
if let Some(a) = amount { assert!(a.parse::<Decimal>().map(|d| d > Decimal::ZERO).unwrap_or(false), "amount must be positive"); } Try / catch
match client.repay(coin, amount).await { Err(e) => { log::error!("repay: {e}"); Err(e.into()) }, Ok(r) => Ok(r) } Prevention
- Supply all required fields (coin) on every repay call
- Keep amount as a Decimal-formatted string
- After upgrades, re-verify builder required fields for repay params
When it happens
Trigger: A required field of `BybitRepayParams` missing from the builder chain (e.g. coin not set after refactoring the conditional setters), or the struct gains a new mandatory field on a Bybit API update.
Common situations: Custom repay flows building params manually; schema drift after upgrades; merge conflicts removing a setter call.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Failed to build BybitNoConvertRepayParams
- Failed to build BybitOpenOrdersParams
- Failed to build BybitSetMarginModeParams
- Failed to build BybitSetLeverageParams
- Failed to build BybitSwitchModeParams
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/186504e71d8e5567.
Report an issue: GitHub.