use crate::conductor::api::error::ConductorApiError;
use crate::conductor::interface::error::InterfaceError;
use holo_hash::AnyDhtHash;
use holochain_cascade::error::CascadeError;
use holochain_secure_primitive::SecurePrimitiveError;
use holochain_serialized_bytes::prelude::SerializedBytesError;
use holochain_state::source_chain::SourceChainError;
use holochain_types::prelude::*;
use thiserror::Error;
use tokio::task::JoinError;
use wasmer::DeserializeError;
#[derive(Error, Debug)]
pub enum RibosomeError {
#[error("Dna error while working with Ribosome: {0}")]
DnaError(#[from] DnaError),
#[error("Wasm runtime error while working with Ribosome: {0}")]
WasmRuntimeError(#[from] wasmer::RuntimeError),
#[error("Serialization error while working with Ribosome: {0}")]
SerializationError(#[from] SerializedBytesError),
#[error("Referenced a zome that doesn't exist: Zome: {0}")]
ZomeNotExists(ZomeName),
#[error("Attempted to call a zome function that doesn't exist: Zome: {0} Fn {1}")]
ZomeFnNotExists(ZomeName, FunctionName),
#[error("An error with entry defs in zome '{0}': {1}")]
EntryDefs(ZomeName, String),
#[error("A mandatory record is missing, dht hash: {0}")]
RecordDeps(AnyDhtHash),
#[error(transparent)]
KeystoreError(#[from] holochain_keystore::KeystoreError),
#[error(transparent)]
DatabaseError(#[from] holochain_sqlite::error::DatabaseError),
#[error(transparent)]
StateQueryError(#[from] holochain_state::query::StateQueryError),
#[error(transparent)]
CascadeError(#[from] CascadeError),
#[error(transparent)]
ConductorApiError(#[from] Box<ConductorApiError>),
#[error(transparent)]
SourceChainError(#[from] SourceChainError),
#[error(transparent)]
InterfaceError(#[from] InterfaceError),
#[error(transparent)]
JoinError(#[from] JoinError),
#[error(transparent)]
InlineZomeError(#[from] InlineZomeError),
#[error(transparent)]
P2pError(#[from] holochain_p2p::HolochainP2pError),
#[error(transparent)]
SecurePrimitive(#[from] SecurePrimitiveError),
#[error("Host function {2} cannot be called from zome function {1} in zome {0}")]
HostFnPermissions(ZomeName, FunctionName, String),
#[error(transparent)]
ZomeTypesError(#[from] holochain_types::zome_types::ZomeTypesError),
#[error(transparent)]
ModuleDeserializeError(#[from] DeserializeError),
#[error(transparent)]
IO(#[from] std::io::Error),
#[error("The callback has an invalid return type: {0}")]
CallbackInvalidReturnType(String),
#[error("The callback has invalid parameters: {0}")]
CallbackInvalidParameters(String),
}
pub type RibosomeResult<T> = Result<T, RibosomeError>;