Skip to content

Commit 130791f

Browse files
grunchclaude
andcommitted
fix: error out on malformed PayBondInvoice payload
The PayBondInvoice arm in print_commands_results silently returned Ok(()) when the payload was not a PaymentRequest, and when the PaymentRequest carried order = None. Both paths skip save_order, so the CLI loses the order context the bond flow depends on while reporting success. Tighten the arm to return Err with the unexpected payload variant or the missing-order condition, and only return Ok(()) after save_order succeeds. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ac419c0 commit 130791f

1 file changed

Lines changed: 25 additions & 22 deletions

File tree

src/parser/dms.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -509,29 +509,32 @@ pub async fn print_commands_results(message: &MessageKind, ctx: &Context) -> Res
509509
}
510510
// mostro-core 0.11: anti-abuse bond invoice sent right after a takebuy/takesell.
511511
Action::PayBondInvoice => {
512-
if let Some(Payload::PaymentRequest(order, invoice, _)) = &message.payload {
513-
handle_pay_bond_invoice_display(order, invoice);
514-
515-
if let Some(order) = order {
516-
if let Some(req_id) = message.request_id {
517-
if let Err(e) = save_order(
518-
order.clone(),
519-
&ctx.trade_keys,
520-
req_id,
521-
ctx.trade_index,
522-
&ctx.pool,
523-
)
524-
.await
525-
{
526-
println!("❌ Failed to save order: {}", e);
527-
return Err(anyhow::anyhow!("Failed to save order: {}", e));
528-
}
529-
print_success_message("Order saved successfully!");
530-
} else {
531-
return Err(anyhow::anyhow!("No request id found in message"));
532-
}
512+
let (order, invoice) = match &message.payload {
513+
Some(Payload::PaymentRequest(order, invoice, _)) => (order, invoice),
514+
other => {
515+
return Err(anyhow::anyhow!(
516+
"PayBondInvoice expected Payload::PaymentRequest, got: {:?}",
517+
other
518+
));
533519
}
534-
}
520+
};
521+
handle_pay_bond_invoice_display(order, invoice);
522+
let order = order.as_ref().ok_or_else(|| {
523+
anyhow::anyhow!("PayBondInvoice payload is missing the SmallOrder")
524+
})?;
525+
let req_id = message
526+
.request_id
527+
.ok_or_else(|| anyhow::anyhow!("No request id found in message"))?;
528+
save_order(
529+
order.clone(),
530+
&ctx.trade_keys,
531+
req_id,
532+
ctx.trade_index,
533+
&ctx.pool,
534+
)
535+
.await
536+
.map_err(|e| anyhow::anyhow!("Failed to save order: {}", e))?;
537+
print_success_message("Order saved successfully!");
535538
Ok(())
536539
}
537540
Action::CantDo => {

0 commit comments

Comments
 (0)