pub use ff_core::engine_error::{
BugKind, ConflictKind, ContentionKind, EngineError, StateKind, ValidationKind,
};
pub use ff_script::engine_error_ext::class;
#[cfg(feature = "valkey-default")]
pub use ff_script::engine_error_ext::{transport_script, transport_script_ref, valkey_kind};
#[cfg(feature = "valkey-default")]
use std::collections::HashMap;
#[cfg(feature = "valkey-default")]
use ff_core::keys::FlowKeyContext;
#[cfg(feature = "valkey-default")]
use ff_core::partition::flow_partition;
#[cfg(feature = "valkey-default")]
use ff_core::types::{EdgeId, FlowId};
#[cfg(feature = "valkey-default")]
use ff_script::error::ScriptError;
#[cfg(feature = "valkey-default")]
pub async fn enrich_dependency_conflict(
client: &ferriskey::Client,
partition_config: &ff_core::partition::PartitionConfig,
flow_id: &FlowId,
edge_id: &EdgeId,
) -> Result<EngineError, EngineError> {
let partition = flow_partition(flow_id, partition_config);
let ctx = FlowKeyContext::new(&partition, flow_id);
let edge_key = ctx.edge(edge_id);
let raw: HashMap<String, String> = match client
.cmd("HGETALL")
.arg(&edge_key)
.execute()
.await
{
Ok(raw) => raw,
Err(transport) => {
return Err(transport_script(ScriptError::Valkey(transport)));
}
};
if raw.is_empty() {
return Err(transport_script(ScriptError::DependencyAlreadyExists));
}
match crate::snapshot::build_edge_snapshot_public(flow_id, edge_id, &raw) {
Ok(existing) => Ok(EngineError::Conflict(ConflictKind::DependencyAlreadyExists {
existing,
})),
Err(_e) => Err(transport_script(ScriptError::DependencyAlreadyExists)),
}
}