nautechsystems/nautilus_trader · error · anyhow::Error
Failed to apply IBOrderTags because IB order JSON is not an
Error message
Failed to apply IBOrderTags because IB order JSON is not an object
What it means
apply_order_field_update maintains a parallel serde_json::Value view of the IBOrder so it can insert-then-restore on failure. If that Value is not a JSON object (an internal invariant — it is initialized from the serialized IBOrder), the update cannot proceed and the function bails.
Source
Thrown at crates/adapters/interactive_brokers/src/execution/transform/tags.rs:102
anyhow::bail!("Invalid IBOrderTags field {field}: {value}");
};
for (field, value) in updates.drain(..) {
apply_order_field_update(ib_order, &mut order_value, &field, value)?;
}
}
Ok(())
}
fn apply_order_field_update(
ib_order: &mut IBOrder,
order_value: &mut Value,
field: &str,
value: Value,
) -> anyhow::Result<()> {
let Some(order_obj) = order_value.as_object_mut() else {
anyhow::bail!("Failed to apply IBOrderTags because IB order JSON is not an object");
};
if !order_obj.contains_key(field) {
anyhow::bail!("Unsupported IBOrderTags field: {field}");
}
let previous = order_obj.insert(field.to_string(), value);
match serde_json::from_value::<IBOrder>(order_value.clone()) {
Ok(updated_order) => {
*ib_order = updated_order;
Ok(())
}
Err(e) => {
let Some(order_obj) = order_value.as_object_mut() else {
anyhow::bail!(
"Failed to restore IB order JSON after invalid IBOrderTags field: {field}"
);View on GitHub (pinned to 18893faf8b)
Solutions
- Verify the IBOrder serializes to a JSON object (custom Serialize impls or newtype wrappers break this) Update the adapter: if IBOrder's serialization changed, the tag-applier's assumption must be fixed in the crate Report as a bug if stock IBOrder triggers it — this is an internal invariant violation
Defensive patterns
Strategy: try-catch
Try / catch
match nautilus_order_to_ib_order(...) {
Err(e) if e.to_string().contains("IB order JSON is not an object") => {
// internal invariant broken; log full order context and report a bug
tracing::error!("adapter invariant violated: {e:#}");
}
r => r?,
} Prevention
- Do not customize IBOrder's serialization
- Keep the adapter crate up to date with any IBOrder struct changes
- Treat this error as a bug report trigger, not a recoverable condition
When it happens
Trigger: apply_ib_order_tag_overlay -> apply_order_field_update when order_value.as_object_mut() returns None. Should only occur if the serialized IBOrder is not an object, e.g. a corrupted or non-struct serialization of IBOrder.
Common situations: Rare; points to an internal inconsistency such as IBOrder serializing to a non-object (custom Serialize impl, version drift between serializer and tag-applier).
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Invalid IBOrderTags payload: expected a JSON object
- Invalid IBOrderTags field {field}: {value}
- Unsupported IBOrderTags field: {field}
- Failed to restore IB order JSON after invalid IBOrderTags fi
- Invalid `MboMsg` parsing combination
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/d6dacae266680e7d.
Report an issue: GitHub.